split() doesn't modify the variable being cut up.  So if you split $_ it
will not be modified.  chop() on the other hand does modify it's argument
(or $_ if no argument is given).

My guess is that you are seeing code like this, or something like it:

foreach $item ( split(/,/, $_) ) {
  # do stuff
}

split() takes the string argument, chops it up based on the given seperator,
and returns a list.  So that code does the same thing as this:

@array = split(/,/, $_);
foreach $item ( @array ) {
  # do stuff
}

I suggest posting a code example next time.

Cheers.

Rob


-----Original Message-----
From: David Milstead [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 11, 2002 8:27 AM
To: [EMAIL PROTECTED]
Subject: Chop and Split


----- Forwarded by David Milstead/Raleigh/IBM on 01/11/2002 08:25 AM -----
 

                    Ask Bjoern Hansen

                    (via RT)                  To:     David
Milstead/Raleigh/IBM@IBMUS                                  
                    <[EMAIL PROTECTED]       cc:

                    g>                        Subject:     [netlabs #262]
[no subject]                                  
                    Sent by: Bug

                    Tracker

                    <[EMAIL PROTECTED]

                    ooper.com>

 

 

                    01/10/2002 06:20 PM

                    Please respond to

                    list-owner

 

 





[[EMAIL PROTECTED] - Thu Jan 10 21:19:49 2002]:

Please send perl questions to the list ([EMAIL PROTECTED]).  This
address is just for questions about the list. :-)

 - ask

> I just subscribed to the beginner's mailing list and the message
said,
> "if you need to get in touch with the human owner of this list" to
send you
> an email.
>
> I have a question about "split" and "chop".
>
> If "split" is used on the $_ variable, what is left in the $_ variable
> after the split is performed?
> Is whatever was split from the $_ variable actually removed from
the $_
> variable?
> I'm trying to figure out a Perl script left by someone else and they
do a
> "chop" to remove a newline character
> and then a split to load some variables with data and the person
said that
> somehow it moves to the next record, so I'm
> thinking the split must remove from the $_ variable whatever you
told it to
> split.  Is that right?
> I'm just learning this stuff.
>
> Thanks.
>
> David Milstead
> [EMAIL PROTECTED]
> 919-855-5242
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to