Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How to split a string

by kutsu (Priest)
on Jan 28, 2005 at 15:51 UTC ( [id://426005]=note: print w/replies, xml ) Need Help??


in reply to How to split a string

Since several people have given the @f = split... answer: why do you want to split a string into each individual character anyway? I ask because there may be an easier way to do this.

If, for example, you only want the 4 character, my $f = substr($s, 4, 1) would work (and is proably easier then $fourthchar = $f[4];, after the split, if that's all you want).

"Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

Replies are listed 'Best First'.
Re^2: How to split a string
by Red_Dragon (Beadle) on Jan 28, 2005 at 21:58 UTC
    The purpose of splitting the string into serialized variables is to use the values in those variables as flags to control reporting granularity. If properly deployed in the Perl code will allow for adjustment of what is reported to a logfile without having to modify the Perl code. The only modification will be to the control string which is housed in an SQL table. Thank you for considering my question.

    R_D

      Then you can use a for or foreach loop (despite the two tutorials for and foreach are exactly the same in perl, super search if you want to know more) to process each field of an array. Like this:

      my $str = '1029576843'; my @f = split //, $str; for (@f) { #$_ is now 0; next run will be 1 and so on print; } #or for my $current_number (@f) { #$current_number is now 0; next run will be 1 and so on print $current_number; }

      "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-19 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found