Tom

I thought taking a string and assigning it to an array would do it 
and I was wrong.

Here is a sample line of source;

  "2004-08-03  23:57         1,712,128 GdiPlus.dll" and the 
recommended split gives me 13 for the number of items. I would like 
an array that has "2004-08-03", "23:57","1,712,128","GdiPlus.dll"  as 
the elements of the array.

Thanks,
Andrew

At 17:40 2007-11-17, Tom Phoenix wrote:
>On 11/16/07, AndrewMcHorney <[EMAIL PROTECTED]> wrote:
>
> > I now got my directory listing into an array of strings. I would
 like
> > to now split up the string into a an array of strings from the
> > original string. For example, I might have a string of "a b c d"
> > and  I now want a 4 element array containing "a", "b", "c", 'd".
> >
> > I did the following but it did not work.
> >
> > @new_dir = @string_array[$index];
>
>What's wrong with it? Was that just some Perl-like code that you typed
>at random, or was there some reason to think that it would do what you
>want?
>
> > The new_dir array is the string from the string array.
> >
> > Where did I go wrong?
>
>Do you want split?
>
>   my @pieces = split / /, "a b c d";
>
>I feel that I'm guessing (badly?) at what you want. Am I close? If
>you're not trying to break up a string on space, what are you trying
>to do?
>
>Hope this helps!
>
>--Tom Phoenix
>Stonehenge Perl Training
>


Tom is right as usual, so not sure what you are confused about.

/etc/skel$ perl -le 'my $string=q/2004-08-03 23:57 1,712,128 GdiPlus.dll/;print 
"\n$string\n";
> my @array=split /\s/, $string; print @array;'

2004-08-03 23:57 1,712,128 GdiPlus.dll

2004-08-0323:571,712,128GdiPlus.dll

/etc/skel$ perl -le 'my $string=q/2004-08-03 23:57 1,712,128 GdiPlus.dll/;print 
"\n$string\n";
my @array=split /\s/, $string; print $array[2];'

2004-08-03 23:57 1,712,128 GdiPlus.dll

1,712,128



#################
# The meaning of split  #
#################
split / /, $foo;
and
split ' ', $foo;
are not the same thing.  
split ' ', $foo is a special case that means to split on all sequences of 
whitespace.  
It means the same thing as split /\s+/, $foo; 




      
____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to