![]() |
|
No such thing as a small change | |
PerlMonks |
more info on splitby NovMonk (Chaplain) |
on Mar 23, 2004 at 19:50 UTC ( #339152=perlquestion: print w/replies, xml ) | Need Help?? |
NovMonk has asked for the wisdom of the Perl Monks concerning the following question:
(Note: This is related to an earlier thread on using strict.) Would someone mind commenting a bit more on this fine suggestion? I've been playing with it all afternoon and am just not getting it. fletch wrote: On an unrelated note, using undef rather than a junk variable is better practice if you don't need one of the return values from split (or wrap the split in parens and subscript it to pull out what you want, e.g. ( $foo, $bar ) = ( split( /:/ ) )[1,4]). I've consulted the tutorials and super search, and there's not a lot on split (in the tutorials)or way too much to find anything relevant (using supersearch). Maybe if I master this, I'll take care of that lack myself. I'm assuming, incidentally, that the last paren in the above is part of the sentence, not the code, as the parens are unbalanced otherwise. Anyway, here's my script at the moment: (the commented out version works great; the lines modeled after Fletch's suggestion above give me the error:
These are only the last couple of lines on a file that scrolls forever.) My input file is 3 line records out of which I need particular bits from the first 2 lines assigned to variables, and then printed once into a new file. The if/elsif/else logic works fine for that, until I try this clever new way of using split. One thing about the second split-- the 4th element (vtext) needs to pick up everything to the end of the line, which is why I tell split I have only 4 elements. I'm hoping someone can point me to more examples of the subscripting used with split, but I accept that I may be too much a novice to see the real error of my ways. I am trying though. Either way, thanks for the enlightenment. Pax, NovMonk
Back to
Seekers of Perl Wisdom
|
|