Re: split function
On Fri, Dec 16, 2011 at 09:36:53PM -0600, Chris Stinemetz wrote: This program does all I need it to do. I am having some difficulty wrapping my head around it though. Mainly the for loop. Did Rob use special varible? If any one can explain it to me so I can have a better understanding that would be great! Is this the part that you don't understand? for my $i (0 .. $#headers) { printf %s=%s\n, $headers[$i], $data[$i]; } There are no special variables here. $#headers is the upper-bound (i.e., last) index of the @headers array. It uses the $# operator[1] to do it. It's equivalent to @headers - 1 (AKA the length of the @headers array minus one, because arrays are 0-indexed in Perl). It seems to be mentioned in 'perldoc perldata', and you can find examples of its usage in a few other documents with something like /\$# (i.e., search forward in the pager). The rest is pretty self explanitory. He's using the printf function with a format string to create the name and value line output. HTH, -- Brandon McCaig bamcc...@gmail.com bamcc...@castopulence.org Castopulence Software https://www.castopulence.org/ Blog http://www.bamccaig.com/ perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }. q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.}; tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say' [1] I don't know if it's a sigil, operator, or something else; but it behaves a bit like both, I guess. signature.asc Description: Digital signature
Re: split function
Hi Chris, On Thu, 15 Dec 2011 15:29:08 -0600 Chris Stinemetz chrisstinem...@gmail.com wrote: Is that your company's policy, or do you just lack root access? If it's the latter, then see the various resources at http://perl-begin.org/topics/cpan/ , so you can see how to install Perl modules from CPAN under your home directory. It isn't a company policy just circumstance. The unix box I'm using doesn't support DNS nameserver lookup or a C compiler. I'm currently using Perl 5.6.1 which doesnt' support local::lib and I can't install perlbrew to upgrade my Perl version due to the fact I can't figure out to get wget to work correctly without having DNS nameserver lookup capabilities. Any suggestions? It sounds like a really mal-functioning UNIX system. Why isn't it getting fixed to support DNS and a C compiler? Regards, Shlomi Fish Thank you, Chris -- - Shlomi Fish http://www.shlomifish.org/ Humanity - Parody of Modern Life - http://shlom.in/humanity Mastering ‘cat’ is almost as difficult as herding cats. — http://www.shlomifish.org/humour/bits/Mastering-Cat/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: split function
On Thursday, December 15, 2011, Chris Stinemetz chrisstinem...@gmail.com wrote: It isn't a company policy just circumstance. The unix box I'm using doesn't support DNS nameserver lookup or a C compiler. I'm currently using Perl 5.6.1 which doesnt' support local::lib and I can't install perlbrew to upgrade my Perl version due to the fact I can't figure out to get wget to work correctly without having DNS nameserver lookup capabilities. You could download perlbrew on another box and scp / rsync / rcp / netcat it over. This, however won't help much without a compiler. Any suggestions? Tried doing what you need under windows? If you tied both of my hands, I probably wouldn't be able to operate a computer either. I'd consider starting by making my system usable by finding and installing the c compiler.
Re: split function
split() splits on whitespace by default. so the \s+/ is optional. $_ = 3 element array; @words = split; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: split function
However I think it's more likely that you need /all/ of the data to be output, so I suggest something like my program below. HTH, Rob use strict; use warnings; my @headers; while (DATA) { if (@headers) { my @data = split; for my $i (0 .. $#headers) { printf %s=%s\n, $headers[$i], $data[$i]; } } else { @headers = split; } } __DATA__ csno rfpi header_1 header_2 header_3 header_4 header_5 header_6 header_7 header_8 header_9 1 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 2 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 3 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 4 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 6 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 7 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 8 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 9 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 10 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 11 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 12 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 **OUTPUT** csno=1 rfpi=1 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=2 rfpi=2 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=3 rfpi=3 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=4 rfpi=1 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=5 rfpi=2 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=6 rfpi=3 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=7 rfpi=1 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=8 rfpi=2 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=9 rfpi=3 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=10 rfpi=1 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=11 rfpi=2 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=12 rfpi=3 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 Tool completed successfully This program does all I need it to do. I am having some difficulty wrapping my head around it though. Mainly the for loop. Did Rob use special varible? If any one can explain it to me so I can have a better understanding that would be great! Thanks, Chris -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: split function
I'm getting a bit closer. There a couple roadblocks I am up against. I am able to split the lines by white space, but for some reason the program isn't capturing the first lines to the @fieldValue array after the @headerNames array. Once I get all the lines to go into the array correctly I would like to combine the @headerNames and @fieldValue arrays. The way I am doing it now only appends the later. I would like the combination to be the below for each elements in the two arrays. any help is greatly appreciated, Chris csno=1 rfpi=1 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $header; my @headerNames; my $field; my @fieldValue; my @apxScript; while (my $line = DATA) { if($line =~ m|(.*_.*\n)|){ $header = $1; @headerNames = split( ,$header); } if($line !~ m|.*_.*\n|){ @fieldValue = split( ,$line); print $fieldValue[0]\n; } } my @apxScript=(@headerNames, @fieldValue); print Dumper \@headerNames; print Dumper \@fieldValue; print Dumper \@apxScript; __DATA__ csno rfpi header_1 header_2 header_3 header_4 header_5 header_6 header_7 header_8 header_9 1 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 2 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 3 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 4 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 6 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 7 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 8 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 9 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 10 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 11 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 12 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: split function
-Original Message- From: Chris Stinemetz [mailto:chrisstinem...@gmail.com] Sent: Thursday, December 15, 2011 10:47 AM To: John W. Krahn Cc: Perl Beginners Subject: Re: split function I'm getting a bit closer. There a couple roadblocks I am up against. I am able to split the lines by white space, but for some reason the program isn't capturing the first lines to the @fieldValue array after the @headerNames array. Once I get all the lines to go into the array correctly I would like to combine the @headerNames and @fieldValue arrays. The way I am doing it now only appends the later. I would like the combination to be the below for each elements in the two arrays. any help is greatly appreciated, Chris csno=1 rfpi=1 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 I have not been following this too closely, but I don't understand the algorithm used to get the above output. #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $header; my @headerNames; my $field; my @fieldValue; my @apxScript; while (my $line = DATA) { if($line =~ m|(.*_.*\n)|){ $header = $1; @headerNames = split( ,$header); } Why not just have an else statement instead of the 'if'? if($line !~ m|.*_.*\n|){ @fieldValue = split( ,$line); print $fieldValue[0]\n; } } Not sure what you are trying to do, but each time through the loop above you are reassigning @fieldValue (I would have named it @fieldValues since arrays usually hold multiple values). Therefore, when you use @fieldValue below, it only contains data from the last line of input. my @apxScript=(@headerNames, @fieldValue); print Dumper \@headerNames; print Dumper \@fieldValue; print Dumper \@apxScript; __DATA__ csno rfpi header_1 header_2 header_3 header_4 header_5 header_6 header_7 header_8 header_9 1 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 2 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 3 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 4 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 6 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 7 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 8 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 9 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 10 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 11 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 12 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 HTH, Ken -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: split function
On 2011-12-14 05:43, Chris Stinemetz wrote: I am trying to split the first element of an array by white space then continue reading the rest of the file. Thus far I am having trouble figuring out how to split the first line. You have an XY problem, you are probably looking for http://search.cpan.org/perldoc?Text::CSV_XS. -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: split function
On Thu, Dec 15, 2011 at 10:42 AM, Dr.Ruud rvtol+use...@isolution.nl wrote: On 2011-12-14 05:43, Chris Stinemetz wrote: I am trying to split the first element of an array by white space then continue reading the rest of the file. Thus far I am having trouble figuring out how to split the first line. You have an XY problem, you are probably looking for http://search.cpan.org/perldoc?Text::CSV_XS. Text::CSV_XS is not an option for me. The unix system I am developing Perl scripts on doesn't allow me to install local libraries from CPAN. Thank you, Chris -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: split function
-Original Message- From: Ken Slater [mailto:kl...@psu.edu] Sent: Thursday, December 15, 2011 11:09 AM To: 'Chris Stinemetz'; 'John W. Krahn' Cc: 'Perl Beginners' Subject: RE: split function -Original Message- From: Chris Stinemetz [mailto:chrisstinem...@gmail.com] Sent: Thursday, December 15, 2011 10:47 AM To: John W. Krahn Cc: Perl Beginners Subject: Re: split function I'm getting a bit closer. There a couple roadblocks I am up against. I am able to split the lines by white space, but for some reason the program isn't capturing the first lines to the @fieldValue array after the @headerNames array. Once I get all the lines to go into the array correctly I would like to combine the @headerNames and @fieldValue arrays. The way I am doing it now only appends the later. I would like the combination to be the below for each elements in the two arrays. any help is greatly appreciated, Chris csno=1 rfpi=1 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 I have not been following this too closely, but I don't understand the algorithm used to get the above output. #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $header; my @headerNames; my $field; my @fieldValue; my @apxScript; while (my $line = DATA) { if($line =~ m|(.*_.*\n)|){ The above line could be more easily written as If ($line =~ m/_/) { based on the fact that underscores apparently only appear in headers. $header = $1; Above line is unecessary @headerNames = split( ,$header); @headerNames = split( ,$line); } Why not just have an else statement instead of the 'if'? if($line !~ m|.*_.*\n|){ @fieldValue = split( ,$line); As mentioned below, you are not saving off any of these values. So at the end, you only have the values from the last line. You need to print here, or save off your data. To print in the format you desire, you could use a counted loop or a hash slice. For example, a hash slice could be used as follows: my %hash; @hash{@headerNames} = @fieldValue; You could then print each key and value on a line (to get them in the desired order you may have to loop over @headerNames to get the key values). print $fieldValue[0]\n; } } Not sure what you are trying to do, but each time through the loop above you are reassigning @fieldValue (I would have named it @fieldValues since arrays usually hold multiple values). Therefore, when you use @fieldValue below, it only contains data from the last line of input. my @apxScript=(@headerNames, @fieldValue); print Dumper \@headerNames; print Dumper \@fieldValue; print Dumper \@apxScript; __DATA__ csno rfpi header_1 header_2 header_3 header_4 header_5 header_6 header_7 header_8 header_9 1 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 2 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 3 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 4 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 6 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 7 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 8 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 9 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 10 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 11 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 12 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 HTH, Ken -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: split function
On 15/12/2011 15:47, Chris Stinemetz wrote: I'm getting a bit closer. There a couple roadblocks I am up against. I am able to split the lines by white space, but for some reason the program isn't capturing the first lines to the @fieldValue array after the @headerNames array. Once I get all the lines to go into the array correctly I would like to combine the @headerNames and @fieldValue arrays. The way I am doing it now only appends the later. I would like the combination to be the below for each elements in the two arrays. any help is greatly appreciated, Chris csno=1 rfpi=1 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $header; my @headerNames; my $field; my @fieldValue; my @apxScript; while (my $line =DATA) { if($line =~ m|(.*_.*\n)|){ $header = $1; @headerNames = split( ,$header); } if($line !~ m|.*_.*\n|){ @fieldValue = split( ,$line); print $fieldValue[0]\n; } } my @apxScript=(@headerNames, @fieldValue); print Dumper \@headerNames; print Dumper \@fieldValue; print Dumper \@apxScript; __DATA__ csno rfpi header_1 header_2 header_3 header_4 header_5 header_6 header_7 header_8 header_9 1 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 2 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 3 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 4 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 6 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 7 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 8 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 9 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 10 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 11 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 12 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 Hey Chris Your program reads lines from DATA and splits every line that doesn't contain an underscore into @fieldValue. Every line of data overwrites the contents of the array, so the end result is that @fieldValue holds the data from the last line of data. What are you hoping for? If you want to retain the /first/ line of data instead of the last then you need only to add a 'last' statement after the '@fieldValue = split( ,$line)' on line 19. However I think it's more likely that you need /all/ of the data to be output, so I suggest something like my program below. HTH, Rob use strict; use warnings; my @headers; while (DATA) { if (@headers) { my @data = split; for my $i (0 .. $#headers) { printf %s=%s\n, $headers[$i], $data[$i]; } } else { @headers = split; } } __DATA__ csno rfpi header_1 header_2 header_3 header_4 header_5 header_6 header_7 header_8 header_9 1 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 2 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 3 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 4 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 6 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 7 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 8 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 9 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 10 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 11 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 12 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 **OUTPUT** csno=1 rfpi=1 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=2 rfpi=2 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=3 rfpi=3 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=4 rfpi=1 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=5 rfpi=2 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=6 rfpi=3 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=7 rfpi=1 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=8 rfpi=2 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=9 rfpi=3 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=10 rfpi=1 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=11 rfpi=2 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 csno=12 rfpi=3 header_1=5.5 header_2=5.5 header_3=5.5 header_4=5.5 header_5=5.5 header_6=5.5 header_7=5.5 header_8=5.5 header_9=5.5 Tool completed successfully -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org
Re: split function
On 15/12/2011 16:09, Ken Slater wrote: I have not been following this too closely, but I don't understand the algorithm used to get the above output. What is that Ken? If you don't understand the question then ask some questions of your own! I would have named it @fieldValues since arrays usually hold multiple values Renaming variables will never fix a problem as long as 'use strict vars' is in effect. It is a gesture towards better code and no more. my @apxScript=(@headerNames, @fieldValue); print Dumper \@headerNames; print Dumper \@fieldValue; print Dumper \@apxScript; HTH, Ken This is the source of the OP's misunderstanding, yet you make no comment at all. Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: split function
Tool completed successfully Thank you Rob! This is what I was trying to accomplish. I'm going to have to research to find out exactly what you did. Thanks agian, Chris -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: split function
To: Perl Beginners Cc: Ken Slater; Chris Stinemetz Subject: Re: split function On 15/12/2011 16:09, Ken Slater wrote: I have not been following this too closely, but I don't understand the algorithm used to get the above output. What is that Ken? If you don't understand the question then ask some questions of your own! I figured out what he wanted and posted regarding this in my second response. I was just confused at first because all his values appeared to be 5.5. I would have named it @fieldValues since arrays usually hold multiple values Renaming variables will never fix a problem as long as 'use strict vars' is in effect. It is a gesture towards better code and no more. True. I did not say it would fix his problem. my @apxScript=(@headerNames, @fieldValue); print Dumper \@headerNames; print Dumper \@fieldValue; print Dumper \@apxScript; HTH, Ken This is the source of the OP's misunderstanding, yet you make no comment at all. Rob The source of his problem was that he was not saving or printing the @fieldValue array (again I would have preferred @fieldValues :-) ) inside the loop. Which I pointed out. Ken -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: split function
Hi Chris, On Thu, 15 Dec 2011 11:58:00 -0600 Chris Stinemetz chrisstinem...@gmail.com wrote: On Thu, Dec 15, 2011 at 10:42 AM, Dr.Ruud rvtol+use...@isolution.nl wrote: On 2011-12-14 05:43, Chris Stinemetz wrote: I am trying to split the first element of an array by white space then continue reading the rest of the file. Thus far I am having trouble figuring out how to split the first line. You have an XY problem, you are probably looking for http://search.cpan.org/perldoc?Text::CSV_XS. Text::CSV_XS is not an option for me. The unix system I am developing Perl scripts on doesn't allow me to install local libraries from CPAN. Is that your company's policy, or do you just lack root access? If it's the latter, then see the various resources at http://perl-begin.org/topics/cpan/ , so you can see how to install Perl modules from CPAN under your home directory. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ First stop for Perl beginners - http://perl-begin.org/ Knuth is not God! It took him two days to build the Roman Empire. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: split function
Is that your company's policy, or do you just lack root access? If it's the latter, then see the various resources at http://perl-begin.org/topics/cpan/ , so you can see how to install Perl modules from CPAN under your home directory. It isn't a company policy just circumstance. The unix box I'm using doesn't support DNS nameserver lookup or a C compiler. I'm currently using Perl 5.6.1 which doesnt' support local::lib and I can't install perlbrew to upgrade my Perl version due to the fact I can't figure out to get wget to work correctly without having DNS nameserver lookup capabilities. Any suggestions? Thank you, Chris -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: split function
Hi Chris, Please check added code to yours, in addition to what John wrote; I am trying to split the first element of an array by white space then continue reading the rest of the file. Thus far I am having trouble figuring out how to split the first line. I would like the first line to be split so it looks like the following with the = sign added. Thank you in advance! Chris csno= rfpi= header_1= header_2= header_3= header_4= header_5= header_6= header_7= header_8= header_9= I am getting the error: Use of implicit split to @_ is deprecated at ./x.pl line 6. #!/usr/bin/perl use warnings; use strict; #while (my @line = DATA) { while (my $line = DATA) { chomp $line; # my $header = split ,$line[0]; if($. == 1){ #$. = Current line number for the last filehandle accessed print $_,=\n for split/\s+/=$line; } else{print $line,\n;} #print $header; } __DATA__ csnorfpiheader_1header_2header_3 header_4header_5header_6header_7 header_8 header_9 1 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 1 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 1 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 2 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 2 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 2 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 3 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 3 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 3 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 4 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 4 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 4 3 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 Please check perldoc -f split, also check perldoc perlvar, for $. = Current line number for the last filehandle accessed Regards, Tim
Re: split function
timothy adigun wrote: Hi Chris, Please check added code to yours, in addition to what John wrote; I am trying to split the first element of an array by white space then continue reading the rest of the file. Thus far I am having trouble figuring out how to split the first line. I would like the first line to be split so it looks like the following with the = sign added. Thank you in advance! Chris csno= rfpi= header_1= header_2= header_3= header_4= header_5= header_6= header_7= header_8= header_9= I am getting the error: Use of implicit split to @_ is deprecated at ./x.pl line 6. #!/usr/bin/perl use warnings; use strict; #while (my @line =DATA) { while (my $line =DATA) { chomp $line; # my $header = split ,$line[0]; if($. == 1){ #$. = Current line number for the last filehandle accessed print $_,=\n for split/\s+/=$line; Don't change split to split/\s+/, it does something different. And you don't need to use chomp as both split and split/\s+/ remove ALL whitespace, including the newline. } else{print $line,\n;} #print $header; } __DATA__ csnorfpiheader_1header_2header_3 header_4header_5header_6header_7 header_8 header_9 1 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 1 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: split function
Chris Stinemetz wrote: I am trying to split the first element of an array by white space then continue reading the rest of the file. Thus far I am having trouble figuring out how to split the first line. I would like the first line to be split so it looks like the following with the = sign added. Thank you in advance! Chris csno= rfpi= header_1= header_2= header_3= header_4= header_5= header_6= header_7= header_8= header_9= I am getting the error: Use of implicit split to @_ is deprecated at ./x.pl line 6. perldoc -f split split /PATTERN/,EXPR,LIMIT split /PATTERN/,EXPR split /PATTERN/ split Splits the string EXPR into a list of strings and returns that list. By default, empty leading fields are preserved, and empty trailing ones are deleted. (If all fields are empty, they are considered to be trailing.) In scalar context, returns the number of fields found. In scalar and void context it splits into the @_ array. Use of split in scalar and void context is deprecated, however, because it clobbers your subroutine arguments. #!/usr/bin/perl use warnings; use strict; while (my @line =DATA) { You don't need a while loop if you are just going to read the whole file into an array. my $header = split ,$line[0]; You are using split in scalar context which means that $header will now contain the number 11 because there are 11 fields in $line[0]. print $header; } __DATA__ csnorfpiheader_1header_2header_3 header_4header_5header_6header_7 header_8 header_9 1 1 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 1 2 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Split function
On 11/29/2010 03:27 AM, Kenneth Wolcott wrote: The reason one should use File::Basename and File::Spec is that you can become platform-independent instead of Windoze-worshipping :-) Ken Wolcott I worship whatever I'm paid to work on. For a Windows shop, the overhead of platform independence is redundant, in the same way you don't care for Windows compatibility in a LAMP application. -- Erez Observations, not opinions. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Split function
ES == Erez Schatz moonb...@gmail.com writes: ES On 11/29/2010 03:27 AM, Kenneth Wolcott wrote: The reason one should use File::Basename and File::Spec is that you can become platform-independent instead of Windoze-worshipping :-) Ken Wolcott ES I worship whatever I'm paid to work on. For a Windows shop, the overhead ES of platform independence is redundant, in the same way you don't care ES for Windows compatibility in a LAMP application. then you worship a false $DEITY! :) uri -- Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- - Perl Code Review , Architecture, Development, Training, Support -- - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com - -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Split function
For a Windows shop, the overhead of platform independence is redundant, Premature optimization much? Brian.
Re: Split function
On 2010-11-29 02:27, Kenneth Wolcott wrote: On Sun, Nov 28, 2010 at 12:31, Dr.Ruudrvtol+use...@isolution.nl wrote: On 2010-11-28 10:54, Chaitanya Yanamadala wrote: How do i split a value like this F:\test\test123\test1233 For example: ruud$ perl -wle 'print for split //, q{F:\test\test123\test1233}' F : -snip- 3 3 The reason one should use File::Basename and File::Spec is that you can become platform-independent instead of Windoze-worshipping :-) What does the operating system have to do with this? OP asked how to split a string, I gave an example how to do it character by character. Another example: ruud$ perl -wle ' print for split /([aeiou])/, q{F:\test\test123\test1233}' F:\t e st\t e st123\t e st1233 -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Split function
Hi; The reason one should use File::Basename and File::Spec is that you can become platform-independent instead of Windoze-worshipping :-) What does the operating system have to do with this? OP asked how to split a string, I gave an example how to do it character by character. My understanding was that the OP wanted to split a path into components using split which I thought was a problem already solved by File::Spec and File::Basename and also provided platform independence; and I thought your example showed a possible problem when splitting using slash one could end up with individual characters which is not at all what I thought the OP was after. The split function does split on the separator for path components, but I thought File::Spec and File::Basename would be clearer (more maintainable) and would be platform independent. Another example: ruud$ perl -wle ' print for split /([aeiou])/, q{F:\test\test123\test1233}' F:\t e st\t e st123\t e st1233 -- Ruud Ken -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Split function
Hi Chaitanya, On Sunday 28 November 2010 11:54:14 Chaitanya Yanamadala wrote: How do i split a value like this F:\test\test123\test1233 please help me with this.. You should use File::Spec (and related modules such as File::Basename) to manipulate path names, instead of using split. See: http://perldoc.perl.org/File/Spec.html For learning about split (which is useful in other cases) see: http://perl-begin.org/tutorials/perl-for-newbies/part2/ Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ My Aphorisms - http://www.shlomifish.org/humour.html rindolf She's a hot chick. But she smokes. go|dfish She can smoke as long as she's smokin'. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Split function
How do i split a value like this F:\test\test123\test1233 use strict; use warnings; my $str='F:\test\test123\test1233'; my @values = split /\\/, $str; print @values; Cheers, Parag On Sun, Nov 28, 2010 at 1:54 AM, Chaitanya Yanamadala dr.virus.in...@gmail.com wrote: How do i split a value like this F:\test\test123\test1233 please help me with this.. Regards Chaitanya
Re: Split function
Take extra caution with the backslash-scapes.. --- use 5.010; use strict; use warnings; my $str1 = F:\test\test123\test1233; #Wrong! Backslash being expanded! my $str2 = 'F:\test\test123\test1233'; my @array1 = split(/\\/, $str1); my @array2 = split(/\\/, $str2); my $n1 = @array1; my $n2 = @array2; say \...@array1 has $n1 element(s)!; # 1 element say \...@array2 has $n2 element(s)!; # 4 elements --- De: Chaitanya Yanamadala dr.virus.in...@gmail.com Assunto: Split function Para: beginners beginners@perl.org Data: Domingo, 28 de Novembro de 2010, 7:54 How do i split a value like this F:\test\test123\test1233 please help me with this.. Regards Chaitanya -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Split function
On 2010-11-28 10:54, Chaitanya Yanamadala wrote: How do i split a value like this F:\test\test123\test1233 For example: ruud$ perl -wle 'print for split //, q{F:\test\test123\test1233}' F : \ t e s t \ t e s t 1 2 3 \ t e s t 1 2 3 3 -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Split function
Hi; On Sun, Nov 28, 2010 at 12:31, Dr.Ruud rvtol+use...@isolution.nl wrote: On 2010-11-28 10:54, Chaitanya Yanamadala wrote: How do i split a value like this F:\test\test123\test1233 For example: ruud$ perl -wle 'print for split //, q{F:\test\test123\test1233}' F : \ t e s t \ t e s t 1 2 3 \ t e s t 1 2 3 3 -- Ruud The reason one should use File::Basename and File::Spec is that you can become platform-independent instead of Windoze-worshipping :-) Ken Wolcott -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Split function
try chomp(my @strm = split(/\s+/, $IntegrationStream)); as your only splitting on 1 space where 2 are present in your string. -Original Message- From: Sayed, Irfan (Irfan) [mailto:[EMAIL PROTECTED] Sent: 30 October 2007 09:38 To: beginners @ perl. org Subject: Split function Hi All, I have one variable which stores the value as follows. 2007-09-07T12:50:26+05:30 aic_8.0_Integration ccvob01 Now my requirement is that I want to store aic_8.0_Integration part of the string in different variable. so what I did was I ran following code. chomp(my @strm = split(/ /, $IntegrationStream)); where $IntegrationStream stores the above string. But the issue is that when I try to access $strm[1] , I am not getting expected result. i.e. aic_8.0_Integration Can you please guide me how should I achieve this. Regards Irfan. This e-mail is from the PA Group. For more information, see www.thepagroup.com. This e-mail may contain confidential information. Only the addressee is permitted to read, copy, distribute or otherwise use this email or any attachments. If you have received it in error, please contact the sender immediately. Any opinion expressed in this e-mail is personal to the sender and may not reflect the opinion of the PA Group. Any e-mail reply to this address may be subject to interception or monitoring for operational reasons or for lawful business practices. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Split function
On Oct 30, 5:37 am, [EMAIL PROTECTED] (Irfan Sayed) wrote: Hi All, I have one variable which stores the value as follows. 2007-09-07T12:50:26+05:30 aic_8.0_Integration ccvob01 Now my requirement is that I want to store aic_8.0_Integration part of the string in different variable. so what I did was I ran following code. chomp(my @strm = split(/ /, $IntegrationStream)); where $IntegrationStream stores the above string. But the issue is that when I try to access $strm[1] , I am not getting expected result. i.e. aic_8.0_Integration Can you please guide me how should I achieve this. Annoyingly, 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; In your statement, you're only splitting on a single whitespace character. There are two spaces in your string, so you're getting a null string as the second element of the returned list, since there is a nothing in between the two space characters. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Split function
Paul Lalli wrote: Annoyingly, 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; Not quite Paul. From perldoc -f split: A split on /\s+/ is like a split(' ') except that any leading whitespace produces a null first field. so ' ' splits at the same places as /\s+/, but also omits any leading empty fields that would result. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Split function
On Oct 30, 1:30 pm, [EMAIL PROTECTED] (Rob Dixon) wrote: Paul Lalli wrote: Annoyingly, 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; Not quite Paul. From perldoc -f split: A split on /\s+/ is like a split(' ') except that any leading whitespace produces a null first field. so ' ' splits at the same places as /\s+/, but also omits any leading empty fields that would result. Good point. Thanks for the correction. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Split function
Andrew Curry schreef: split(/\s+/, ... Most of the times you think you need /\s+/ with split, you actually want q{ }. See `perldoc -f split`. -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: split function help
On Tue, 2006-08-29 at 21:23 +0800, Sayed, Irfan (Irfan) wrote: my @vob_path = split(/ /, $vob_list); where $vob_list contains the I am not crash hot on the split yet, but try split( /\s+/, $vob_list ) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function help
Sayed, Irfan (Irfan) schreef: my @vob_path = split(/ /, $vob_list); Maybe you need split(' ', $vob_list) See perldoc -f split. -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function help
On 08/29/2006 08:23 AM, Sayed, Irfan (Irfan) wrote: Hi All, I need to use the split function in perl script. * /vobs/apache_log4j /usr/add-on/puccase_vob01/ccvob01/apache_log4j.vbs public (replicated) Above line i need to split in following order * /vobs/apache_log4j /usr/add-on/puccase_vob01/ccvob01/apache_log4j.vbs public (replicated) I tried the following command my @vob_path = split(/ /, $vob_list); where $vob_list contains the actual line. but i am not getting the output as i want. can anybody please help. Regards irfan You didn't say what was wrong with your output, but I think that you can fix it by creating a character class containing both space and newline and splitting on that: use Data::Dumper; my $vob_list = q{* /vobs/apache_log4j /usr/add-on/puccase_vob01/ccvob01/apache_log4j.vbs public (replicated)}; my @vob_path = split (/[ \n]/, $vob_list); print Dumper([EMAIL PROTECTED]); __END__ Next time, rather than to say I am not getting the output as I want, instead say something like The output is wrong because I am getting /vobs/apache_log4j inside the same element as /usr/add-on/ HTH PS. Thanks for spelling words properly. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function help
Ken Foskey schreef: split( /\s+/, $vob_list ) There is a difference between that and split( ' ', $vob_list ) The latter skips whitespace at the start. perl -e ' $_ = qq{ abc def\tghi\njkl} ; @_ = split /\s+/ ; $ = qq{\n} ; print [EMAIL PROTECTED] ' [ abc def ghi jkl] perl -e ' $_ = qq{ abc def\tghi\njkl} ; @_ = split q{ } ; $ = qq{\n} ; print [EMAIL PROTECTED] ' [abc def ghi jkl] -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function
On Jul 19, 2006, at 9:57, Sayed, Irfan ((Irfan)) wrote: I need to split following string cs_backup_restore_cmvobsvr1mum the output which i am looking for is cs_backup_restore and _cmvobsvr1mum Which is the criteria, everything up to the last underscore? -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: split function
-Original Message- From: Xavier Noria [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 19, 2006 1:33 PM To: Perl Beginners Subject: Re: split function On Jul 19, 2006, at 9:57, Sayed, Irfan ((Irfan)) wrote: I need to split following string cs_backup_restore_cmvobsvr1mum the output which i am looking for is cs_backup_restore and _cmvobsvr1mum Which is the criteria, everything up to the last underscore? -- fxn hi, I think criteria shud be _ but I need output in following manner cs_backup_restore and _cmvobsvr1mum regards irfan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function
On Jul 19, 2006, at 10:05, Sayed, Irfan ((Irfan)) wrote: I think criteria shud be _ but I need output in following manner That criteria is ambiguous becasue there are several _s and you need to deal with them differently, that is, ignoring some and splitting on some. Can you be more specific? -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: split function
I need to split following string cs_backup_restore_cmvobsvr1mum the output which i am looking for is cs_backup_restore and _cmvobsvr1mum I think this will work fine if you are bothered about the last word after underscore: Ajay perl -e 'my $str='cs_backup_restore_cmvobsvr1mum'; my @arr= ($str=~/(.+)_(.+)/); print join \n,@arr,\n;' cs_backup_restore cmvobsvr1mum Ajay Thanks, Ajay -Original Message- From: Xavier Noria [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 19, 2006 1:33 PM To: Perl Beginners Subject: Re: split function On Jul 19, 2006, at 9:57, Sayed, Irfan ((Irfan)) wrote: I need to split following string cs_backup_restore_cmvobsvr1mum the output which i am looking for is cs_backup_restore and _cmvobsvr1mum Which is the criteria, everything up to the last underscore? -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function
Sayed, Irfan (Irfan) schreef: I need to split following string cs_backup_restore_cmvobsvr1mum the output which i am looking for is cs_backup_restore and _cmvobsvr1mum $ perl -Mstrict -wle ' $_ = cs_backup_restore_cmvobsvr1mum ; @_ = split /(_)/ ; # print for @_ ; $ = \t ; print for @_[0..$#_-2], @_[-2..-1], ; $ =; print @_[0..$#_-2] and @_[-2..-1] ; ' cs _ backup _ restore _ cmvobsvr1mum cs_backup_restore and _cmvobsvr1mum -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function
On 07/19/2006 02:57 AM, Sayed, Irfan (Irfan) wrote: Hi, I need to split following string cs_backup_restore_cmvobsvr1mum the output which i am looking for is cs_backup_restore and _cmvobsvr1mum can anybody plz help regards irfan. Sayed, Irfan; your questions are too basic. Any Perl programmer who has read the first seven documents referred by perldoc perl will know the questions you're asking. Please read these: perldoc perlintro perldoc perltoc perldoc perlreftut perldoc perldsc perldoc perllol perldoc perlrequick perldoc perlretut Read them and do all of the examples in them. Whatever program you're writing, stop writing it and take a couple of days to learn Perl. Then return to your program with newly opened eyes. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function
Hi Sayed, I could not get your exact requirement. Here is one way to get the output shown by you. $string = 'cs_backup_restore_cmvobsvr1mum'; ($first, $second) = $string =~ /(.+)(_[^_]+)/s; print First: $first\nSecond: $second; output: First: cs_backup_restore Second: _cmvobsvr1mum Regards, Prasad Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] .. -Original Message- From: Xavier Noria [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 19, 2006 1:33 PM To: Perl Beginners Subject: Re: split function On Jul 19, 2006, at 9:57, Sayed, Irfan ((Irfan)) wrote: I need to split following string cs_backup_restore_cmvobsvr1mum the output which i am looking for is cs_backup_restore and _cmvobsvr1mum Which is the criteria, everything up to the last underscore? -- fxn hi, I think criteria shud be _ but I need output in following manner cs_backup_restore and _cmvobsvr1mum regards irfan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Split function help
Irfan J Sayed wrote: Hi, I have a following line/statement stored in variable $test deliver.Admin_Irfan_Project.20060413.212355 i want to split this line in . and store in array. I am using following code my @name = Split(/./, $test); split uses regular expressions to identify where to split the string. The expression you supplied, /./, would split on everything. In your particular case you could also split on /\W/. But this isn't a very good choice, just an example. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Split function help
Dear Irfan, i think for the code you can try the below, ($some_thing1,$some_thing2,$something_3)=split($test,.) Regards Mazhar On 4/25/06, Tom Allison [EMAIL PROTECTED] wrote: Irfan J Sayed wrote: Hi, I have a following line/statement stored in variable $test deliver.Admin_Irfan_Project.20060413.212355 i want to split this line in . and store in array. I am using following code my @name = Split(/./, $test); split uses regular expressions to identify where to split the string. The expression you supplied, /./, would split on everything. In your particular case you could also split on /\W/. But this isn't a very good choice, just an example. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Split function help
Mazhar wrote: Dear Irfan, i think for the code you can try the below, ($some_thing1,$some_thing2,$something_3)=split($test,.) You have the split arguments reversed :) Also, don't use double quotes when there is nothing to interpolate. And space them out so its easier to read :) And use my() so its strict safe: my @things = split '.', $test; or with variables and () with the split: my($thing_a, $thing_b) = split('.', $test); HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Split function help
On Mon, 17 Apr 2006, Irfan J Sayed wrote: Snip |i want to split this line in . and store in array. |I am using following code |my @name = Split(/./, $test); /Snip Try escaping . with a \. HTH, Senthil -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Split function help
Hello, In case of linux you have to escape the . and the function name should be split and not Split. Not quite sure about windows. Regards Nishanth --- M Senthil Kumar [EMAIL PROTECTED] wrote: On Mon, 17 Apr 2006, Irfan J Sayed wrote: Snip |i want to split this line in . and store in array. |I am using following code |my @name = Split(/./, $test); /Snip Try escaping . with a \. HTH, Senthil -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Split function help
On Mon, 17 Apr 2006, M Senthil Kumar wrote: |On Mon, 17 Apr 2006, Irfan J Sayed wrote: | |Snip ||i want to split this line in . and store in array. ||I am using following code ||my @name = Split(/./, $test); |/Snip | |Try escaping . with a \. | |HTH, | |Senthil | And oh I forgot: Split should have been split Senthil -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function in perl
On Apr 17, 2006, at 10:30, Irfan J Sayed wrote: Hi, I have a following line stored in one variable $test. deliver.Admin_Irfan_Project.20060413.212355 . I need to split this line into the words and store the output in array. words should like this. deliver admin irfan project 20060413 212355 I am using following code to split this line $test =~ s/^\s+//; @array = split(/\W/, $test); Problem is that _ belongs to \w or, equivalently, it does not belong to \W. For that particular example it is enough to include _ in the regexp: % perl -wle 'print for split /[\W_]/, deliver.Admin_Irfan_Project. 20060413.212355' deliver Admin Irfan Project 20060413 212355 -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function in perl
Xavier Noria schreef: split /[\W_]/ Alternatives: split /\W|_/ split /[^[:alnum:]]/ -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Split function
Hi, To run/use Split function in the perl script , is it necessary to include/add any perl module ? No no need. It is a built in function. perldoc -f split -- Regards, Edward WIJAYAA Institute For Infocomm Research - Disclaimer - This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function
Hi! Can the perl split function split a random 40 character string into five 8 character strings? With random I mean that there is no special pattern in the 40 character string that can be used as split markers. This smells like homework? (just a reminder to the gurus, it is that time of the year again)... perldoc -f split perldoc -f substr perldoc -f unpack Just one way #!/usr/local/bin/perl use strict; use warnings; my $long_string = 01234567 x 5; my @strings = unpack('A8' x 5, $long_string); print join(',', @strings) . \n; http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function
C r wrote: Can the perl split function split a random 40 character string into five 8 character strings? With random I mean that there is no special pattern in the 40 character string that can be used as split markers. Don't know, but in any case the m// operator is a better way to do that: my @parts = $string =~ /.{8}/g; -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function
On Tue, 14 Sep 2004, c r wrote: Can the perl split function split a random 40 character string into five 8 character strings? With random I mean that there is no special pattern in the 40 character string that can be used as split markers. Wouldn't substr make more sense, or a regex? $ cat ~/bin/test.pl #!/usr/bin/perl -w use strict; my $string = qq[a2345678b2345678c2345678d2345678e2345678]; my ($a,$b,$c,$d,$e) = $string =~ m/(.{8})(.{8})(.{8})(.{8})(.{8})/; print qq[ \$string = $string \$a = $a \$b = $b \$c = $c \$d = $d \$e = $e ]; $ perl ~/bin/test.pl $string = a2345678b2345678c2345678d2345678e2345678 $a = a2345678 $b = b2345678 $c = c2345678 $d = d2345678 $e = e2345678 $ This seems to be what you want, right ? -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: split function
Can the perl split function split a random 40 character string into five 8 character strings? With random I mean that there is no special pattern in the 40 character string that can be used as split markers. How about unpack? @eights = unpack(A8 x (length($string)/8), $string); Thanks Jim --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function
c r wrote: Hi! Hello, Can the perl split function split a random 40 character string into five 8 character strings? No. With random I mean that there is no special pattern in the 40 character string that can be used as split markers. You should probably use a match operator. my @strings = $string =~ /.{1,8}/sg; Of course you could use substr or unpack as well. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function - from input
Stephen Kelly wrote: hi there Hello, i'm trying to split a string from a line of text in a file - the split delimiter is a tab character '\t' - i then need to compare the 2 bits on either side of the tab to see if they are equal - if not eq - i write to tidy else i write to mess ? confused - this bit of code is giving me empty files ? You haven't removed the end of line character(s) so the two fields will never be equal. use warnings; use strict; while (INPUT) { You need to chomp() here: chomp; next if ($_=~/^\#/); #if line begins with a # next if ($_=~/^\s*(\#|$)/); #if line is blank The first line is not needed as the second line does the same thing. next if /^\s*(?:#|$)/; if ( $_ =~/\w/) {print MESS $_} The quotes nor the use of $_ are requied. print MESS if /\w/; if ( $_ !~/[A-Za-z]/) {print MESS $_} else {print TIDY $_} # split the string into 2 parts string 1, 2 separated with a tab. @_= split(/\t/,$_); # compare the first element of the list with the last element. if (@_[0] eq @_[1]) You are using array slices when you should be using scalars. if ( $_[0] eq $_[1] ) {print MESS $_} else { print TIDY $_} } A more perl-ish way to write that: while ( INPUT ) { next if /^\s*(?:#|$)/; #if line begins with a # or line is blank print MESS if /\w/; print { /[A-Za-z]/ ? *TIDY : *MESS } $_; # split the string into 2 parts string 1, 2 separated with a tab. my ( $first, $second ) = split /\t/; # compare the first element of the list with the last element. print { $first eq $second ? *MESS : *TIDY } $_; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function - from input
John W. Krahn wrote: A more perl-ish way to write that: while ( INPUT ) { Oops, forgot to chomp. chomp; next if /^\s*(?:#|$)/; #if line begins with a # or line is blank print MESS if /\w/; print { /[A-Za-z]/ ? *TIDY : *MESS } $_; # split the string into 2 parts string 1, 2 separated with a tab. my ( $first, $second ) = split /\t/; # compare the first element of the list with the last element. print { $first eq $second ? *MESS : *TIDY } $_; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: split function problem.
hi, $name_with_id looks like a comma separated list you can simply *not tested*: ($name,$id) = split (/,/, $name_with_id) -- franck Sara wrote: An input string like; $name_with_id = Deiley, Sara Jr., 1234; another example could be $name_with_id = DEILEY SARA, Jr,. 123; Two things are for sure in it always. 1- First part contains the alphabets (caps or small) with any number of commas and periods (full stops) in between or at the end. and then always a white space, followed by: 2- the last part contains the digit/number which could be 2 - 5 digits long. What I am trying to do is to split this string in two parts first part with alphatbets and second part with digits separately and assign them to two new variables i.e $name and $id. I am trying this; $name_with_id = Deiley, Sara Jr., 1234; split (/[^\d]+/, $name_with_id) = ($name,$id); print name: $name and ID: $id; Error: Can't modify split in scalar assignment at line 3; Any help or alternative way to do this. Thanks, Sara. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: split function problem.
I would prbally add a seperator less common than a comma such as || to use the split funciton on... james hi, $name_with_id looks like a comma separated list you can simply *not tested*: ($name,$id) = split (/,/, $name_with_id) -- franck Sara wrote: An input string like; $name_with_id = Deiley, Sara Jr., 1234; another example could be $name_with_id = DEILEY SARA, Jr,. 123; Two things are for sure in it always. 1- First part contains the alphabets (caps or small) with any number of commas and periods (full stops) in between or at the end. and then always a white space, followed by: 2- the last part contains the digit/number which could be 2 - 5 digits long. What I am trying to do is to split this string in two parts first part with alphatbets and second part with digits separately and assign them to two new variables i.e $name and $id. I am trying this; $name_with_id = Deiley, Sara Jr., 1234; split (/[^\d]+/, $name_with_id) = ($name,$id); print name: $name and ID: $id; Error: Can't modify split in scalar assignment at line 3; Any help or alternative way to do this. Thanks, Sara. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: split function problem.
Sara [EMAIL PROTECTED] wrote: : : An input string like; : : $name_with_id = Deiley, Sara Jr., 1234; : : another example could be : : $name_with_id = DEILEY SARA, Jr,. 123; : : Two things are for sure in it always. : : 1- First part contains the alphabets (caps or small) with any : number of commas and periods (full stops) in between or at the end. : : and then always a white space, followed by: : : 2- the last part contains the digit/number which could be 2 - : 5 digits long. : I am trying this; : : $name_with_id = Deiley, Sara Jr., 1234; : : split (/[^\d]+/, $name_with_id) = ($name,$id); [^\d]+ will match anything that is *not* a digit. and appears more that one time in the search string. In our example string, it splits on: Deiley, Sara Jr., . All of which is not a digit. To find the last part we could use: \d{2,5} William of Occam gave pretty good advice: Entities should not be multiplied unnecessarily. : print name: $name and ID: $id; : : Error: Can't modify split in scalar assignment at line 3; Unlike 'substr', split can only be on the right side of an equation. If you set split equal to something, you'll get the error above. So this would seem more logical: my ($name,$id) = split (/\d{2,5}/, $name_with_id); The problem is that split discards the part we're looking for: \d{2,5} unless we place it in parenthesis. my( $name, $id ) = split / (\d{2,5})/, $name_with_id; This should throw away the space and keep the digits: use strict; use warnings; use Data::Dumper; my $name_with_id = Deiley, Sara Jr., 1234; print Dumper [ split / (\d{2,5})$/, $name_with_id ]; __END__ HTH, Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: split function problem.
I am extremely thankful to you for your help. I always loved your way of teaching and explaining the code bit by bit. One more question I searched the google for HTH abbreviation but didn't find anything. Can you tell me what does it mean? Thanks, Sara, :)) - Original Message - From: Charles K. Clarkson [EMAIL PROTECTED] To: 'Sara' [EMAIL PROTECTED]; 'org' [EMAIL PROTECTED] Sent: Wednesday, July 09, 2003 6:30 AM Subject: RE: split function problem. Sara [EMAIL PROTECTED] wrote: : : An input string like; : : $name_with_id = Deiley, Sara Jr., 1234; : : another example could be : : $name_with_id = DEILEY SARA, Jr,. 123; : : Two things are for sure in it always. : : 1- First part contains the alphabets (caps or small) with any : number of commas and periods (full stops) in between or at the end. : : and then always a white space, followed by: : : 2- the last part contains the digit/number which could be 2 - : 5 digits long. : I am trying this; : : $name_with_id = Deiley, Sara Jr., 1234; : : split (/[^\d]+/, $name_with_id) = ($name,$id); [^\d]+ will match anything that is *not* a digit. and appears more that one time in the search string. In our example string, it splits on: Deiley, Sara Jr., . All of which is not a digit. To find the last part we could use: \d{2,5} William of Occam gave pretty good advice: Entities should not be multiplied unnecessarily. : print name: $name and ID: $id; : : Error: Can't modify split in scalar assignment at line 3; Unlike 'substr', split can only be on the right side of an equation. If you set split equal to something, you'll get the error above. So this would seem more logical: my ($name,$id) = split (/\d{2,5}/, $name_with_id); The problem is that split discards the part we're looking for: \d{2,5} unless we place it in parenthesis. my( $name, $id ) = split / (\d{2,5})/, $name_with_id; This should throw away the space and keep the digits: use strict; use warnings; use Data::Dumper; my $name_with_id = Deiley, Sara Jr., 1234; print Dumper [ split / (\d{2,5})$/, $name_with_id ]; __END__ HTH, Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: split function problem.
Sara [EMAIL PROTECTED] wrote: : : One more question I searched the google for : HTH abbreviation but didn't find anything. : : Can you tell me what does it mean? Hope That Helps And sometimes: Hotter Than Hell :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: split function problem.
Sara wrote: I am extremely thankful to you for your help. I always loved your way of teaching and explaining the code bit by bit. One more question I searched the google for HTH abbreviation but didn't find anything. Can you tell me what does it mean? http://info.astrian.net/jargon/terms/h.html#HTH Jargon dictionary is often a good place to track down that kind of stuff, but don't waste to much time there ;-) http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: split function using . for the pattern
Did you remember to represent '.' as '\.'? -Original Message- From: [EMAIL PROTECTED] [mailto:bengleto;calpoly.edu] Sent: Wednesday, October 30, 2002 9:39 AM To: [EMAIL PROTECTED] Subject: split function using . for the pattern I have a string that I want to split into an array 10.30.02 I cant get it to split up the string at the .s. Do I have to do something different because . is an ambiguous character? Thank you Brian -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: split function using . for the pattern
escape the . with \ in your split statement -Original Message- From: [EMAIL PROTECTED] [mailto:bengleto;calpoly.edu] Sent: Wednesday, October 30, 2002 12:39 PM To: [EMAIL PROTECTED] Subject: split function using . for the pattern I have a string that I want to split into an array 10.30.02 I cant get it to split up the string at the .s. Do I have to do something different because . is an ambiguous character? Thank you Brian -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Split function
localtime() actually returns an array, so if you do this: @date = localtime(); Then your array will be populated with the information you're looking for. Personally, I prefer to do it this way: ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); Just remember that you have to add 1 to the $mon variable, and 1900 to the $year variable. -Original Message- From: Kevin Butters [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 12, 2002 5:16 PM To: [EMAIL PROTECTED] Subject: Split function I am difficulty in using the split function to extract the current date from the @date_time variable. #! /usr/bin/perl -w #Class 4 assignment # define hash use strict; my %days; %days = ( 'mon' = 'Monday', 'tue' = 'Tuesday', 'wed' = 'Wednesday', 'thu' = 'Thursday', 'fri' = 'Friday', 'sat' = 'Saturday', 'sun' = 'Sunday', ); # Define $date_time varible my $date_time = localtime; print $date_time; split $date_time,/ /; __ Do You Yahoo!? Send FREE Valentine eCards with Yahoo! Greetings! http://greetings.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Split function
On Feb 12, Kevin Butters said: my $date_time = localtime; print $date_time; split $date_time,/ /; You've got that backwards. And where are you storing the results? @parts = split / /, $date_time; And you might want to use split / +/ or split ' ' instead. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: split function question
--- Brian Bukeavich [EMAIL PROTECTED] wrote: I need a little help with the split function. I'm trying to split a line based on comma delimeters(,), but when I use the syntax below I don't get the results I expect. What am I doing wrong? Is there a an special escape sequence for a comma? my @asLine = split (/,/, $_); Just a quick guess, but much of the comma-delimited data that I see has quoted fields that have commas embedded in the quotes: Poe, Curtis, 34, Aspiring Screenwriter, Programmer Trying to split the above line on commas will result in five fields instead of three. You should probably use a module like Text::CSV or something similar. If you show us some sample input, expected output, and actual output, we can offer better advice. Cheers, Curtis Poe = Senior Programmer Onsite! Technology (http://www.onsitetech.com/) Ovid on http://www.perlmonks.org/ __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
RE: split function question
perl -e 'print Enter your values as 1,2,3...:; $_=; chomp; my @asLine=split (/,/, $_); foreach (@asLine) { print asLine[.$i++.]=$_\n; }' You may want to see what you have print $_\n for example just before you try the split ... -Original Message- From: Brian Bukeavich [mailto:[EMAIL PROTECTED]] Sent: June 28, 2001 15:38 To: [EMAIL PROTECTED] Subject: split function question I need a little help with the split function. I'm trying to split a line based on comma delimeters(,), but when I use the syntax below I don't get the results I expect. What am I doing wrong? Is there a an special escape sequence for a comma? my @asLine = split (/,/, $_); Thanks _ Get your FREE download of MSN Explorer at http://explorer.msn.com