Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Split Help

by Sandy (Curate)
on Mar 16, 2009 at 20:32 UTC ( #751023=note: print w/ replies, xml ) Need Help??


in reply to Split Help

Hi

works for me.

[sandy]perl -e '$x="hello"; $y="thishelloyouhellotoday"; @a=split /$x/ +,$y; print "@a\n";' this you today [sandy]
could you give us an example of what doesn't work?


Comment on Re: Split Help
Download Code
Re^2: Split Help
by de2425 (Sexton) on Mar 16, 2009 at 20:50 UTC

    Thanks for the super quick response! What I'm trying to do is to use the split to count the occurrences of the filename with the file. I just checked with a print statement and I am getting a split but for some reason, I cannot get the correct number of splits. I can visually count them but I can't seem to get any goot results from something like:

    print "$#lines\n";

      $#lines contains the last index of the array @lines which may or may not be one less than the actual number of elements in the array @lines.   To get the actual number of elements of an array you must use the array in scalar context:

      print scalar @lines, "\n";

      Hmm.. here you are saying

      print "$#lines\n";

      but in the OP

      @line=split(/$variable/,$_);

      Maybe you mean @lines? or perhaps $#line?

      If you include

      use warnings;

      at the top of your program, perl helps you emitting a warning if, by typo, you are using a variable only once.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://751023]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2015-07-06 13:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls