Split file in perl




















Another special case helps to retain the separator or parts of it. Toggle navigation Perl Maven. Standard output, standard error and command line redirection Warning when something goes wrong What does die do?

Unknown warnings category Can't use string Symbolic references in Perl Can't locate Can't locate object method " Useless use of hash element in void context Useless use of private variable in void context readline on closed filehandle in Perl Possible precedence issue with control flow operator Scalar value You can limit the number of sections the string will be split into.

You can do this by passing in a positive integer as the third argument. In this example, we're splitting our data into 3 fields - even though there are 4 occurrences of the delimiter:. Sometimes, when splitting on a pattern, you want the delimiter in the result of the split.

You can do this by capturing the characters you want to keep inside parenthesis. Let's do our regular expression example again, but this time we'll keep the numbers in the result:. If you know a bit about your data, you could split it directly into a hash instead of an array:. Here is the output of the same program but with this new data:. Revision: 1. That would reveal a lot of problems with your programming that aren't otherwise apparent.

I heartily agree with you that my Perl programming is poor. Just trying to help you improve : btw my solution is much golfier than daxim's :P — Borodin. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.

The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked 3. Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled. Accept all cookies Customize settings.



0コメント

  • 1000 / 1000