FAQ
Hello all,

I have a line of text and numbers each seperated by multiple or single
spaces looks like this

abc 123 33545 789

I wanted to split the above line and store each column value in a specific
variable and later print,

Below is the code I am using but it's not working as I desire,

$Avg=$first[$i];
chomp($Avg);
($label,$TD,$YT,$M,$L,$Y,$W)= split (/i\s*/,$Avg);
print "$label,$TD,$YT,$M,$L,$Y,$W\n";

I used "\s*" in split, so I do not have worry about counting the spaces or
tabs between each field

Any suggestions on what am I doing wrong..?

Regards

Search Discussions

  • Wiggins d Anconia at Jun 28, 2004 at 3:38 pm

    Hello all,

    I have a line of text and numbers each seperated by multiple or single
    spaces looks like this

    abc 123 33545 789

    I wanted to split the above line and store each column value in a specific
    variable and later print,

    Below is the code I am using but it's not working as I desire,

    $Avg=$first[$i];
    chomp($Avg);
    ($label,$TD,$YT,$M,$L,$Y,$W)= split (/i\s*/,$Avg);
    print "$label,$TD,$YT,$M,$L,$Y,$W\n";

    I used "\s*" in split, so I do not have worry about counting the spaces or
    tabs between each field
    What do you think the 'i' is doing in the regexp above? You are saying
    to match the letter 'i' followed by zero or more spaces. Removing the
    'i' will cause a match on every non-whitespace character. You want to
    split on 1-or-more white space characters. Try /\s+/ as your pattern
    instead.
    Any suggestions on what am I doing wrong..?
    I assume your data can have as many fields as you split into?

    http://danconia.org
  • James Edward Gray II at Jun 28, 2004 at 3:42 pm

    On Jun 28, 2004, at 10:19 AM, Naser Ali wrote:

    Hello all,

    I have a line of text and numbers each seperated by multiple or single
    spaces looks like this

    abc 123 33545 789

    I wanted to split the above line and store each column value in a
    specific
    variable and later print,

    Below is the code I am using but it's not working as I desire,

    $Avg=$first[$i];
    chomp($Avg);
    ($label,$TD,$YT,$M,$L,$Y,$W)= split (/i\s*/,$Avg);
    print "$label,$TD,$YT,$M,$L,$Y,$W\n";

    I used "\s*" in split, so I do not have worry about counting the
    spaces or
    tabs between each field

    Any suggestions on what am I doing wrong..?
    There is an extra character at the front of that regex, an i character.

    James
  • Charles K. Clarkson at Jun 28, 2004 at 3:44 pm
    From: Naser Ali wrote:

    : Hello all,
    :
    : I have a line of text and numbers each seperated by
    : multiple or single spaces looks like this
    :
    : abc 123 33545 789
    :
    : I wanted to split the above line and store each
    : column value in a specific variable and later
    : print,

    use strict;
    use warnings;

    my $foo = 'abc 123 33545 789';
    my @fields = split ' ', $foo;

    print join ', ', @fields;


    __END__


    : Below is the code I am using but it's not working
    : as I desire,
    :
    : $Avg=$first[$i];
    : chomp($Avg);
    : ($label,$TD,$YT,$M,$L,$Y,$W)= split (/i\s*/,$Avg);


    What is the 'i' for? The example above doesn't
    have any 'i's in it. What is really in $Avg?

    The example above only had 4 fields. This seems
    to be looking for 7 fields. Which is it 4 or 7?


    : print "$label,$TD,$YT,$M,$L,$Y,$W\n";
    :
    : I used "\s*" in split, so I do not have worry about
    : counting the spaces or tabs between each field

    Read perlfunc 'split'. Splitting on white space is
    covered there. '\s+' would match on more than one space.
    '\s*' matches on zero or more spaces. Most of the time
    I find " split ' ' " does what I need.


    HTH,

    Charles K. Clarkson
    --
    Mobile Homes Specialist
    254 968-8328
  • Gunnar Hjalmarsson at Jun 28, 2004 at 3:59 pm

    Naser Ali wrote:
    Any suggestions on what am I doing wrong..?
    Why do you want a scalar variable for each value? Why not using an
    array instead?

    And you seem not to be using strictures and warnings.

    Others have helped you with the pattern passed to split().

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
  • Naser Ali at Jun 28, 2004 at 3:59 pm
    There are actually 7 fields total. The name Avg does not mean anything. I
    just copied and pasted an old code to save some time in editing while
    testing this functionality. Also "i" is a typo. should have put all the
    seven fields. So this is how it should look like

    abc 123 33545 789 52635 87236 7828

    I tried with, after removing "i"

    " split ' ' " and " split (/\s+/,$Avg) " as well, but no success

    Thanks


    -----Original Message-----
    From: Charles K. Clarkson
    Sent: Monday, June 28, 2004 11:44 AM
    To: 'Naser Ali'; beginners@perl.org
    Subject: RE: string seperated by multiple spaces


    From: Naser Ali wrote:

    : Hello all,
    :
    : I have a line of text and numbers each seperated by
    : multiple or single spaces looks like this
    :
    : abc 123 33545 789
    :
    : I wanted to split the above line and store each
    : column value in a specific variable and later
    : print,

    use strict;
    use warnings;

    my $foo = 'abc 123 33545 789';
    my @fields = split ' ', $foo;

    print join ', ', @fields;


    __END__


    : Below is the code I am using but it's not working
    : as I desire,
    :
    : $Avg=$first[$i];
    : chomp($Avg);
    : ($label,$TD,$YT,$M,$L,$Y,$W)= split (/i\s*/,$Avg);


    What is the 'i' for? The example above doesn't
    have any 'i's in it. What is really in $Avg?

    The example above only had 4 fields. This seems
    to be looking for 7 fields. Which is it 4 or 7?


    : print "$label,$TD,$YT,$M,$L,$Y,$W\n";
    :
    : I used "\s*" in split, so I do not have worry about
    : counting the spaces or tabs between each field

    Read perlfunc 'split'. Splitting on white space is
    covered there. '\s+' would match on more than one space.
    '\s*' matches on zero or more spaces. Most of the time
    I find " split ' ' " does what I need.


    HTH,

    Charles K. Clarkson
    --
    Mobile Homes Specialist
    254 968-8328
  • Gunnar Hjalmarsson at Jun 28, 2004 at 4:05 pm

    Naser Ali wrote:
    I tried with, after removing "i"

    " split ' ' " and " split (/\s+/,$Avg) " as well, but no success
    In that case there is a problem also with a part of your code that you
    did not show us.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
  • Naser Ali at Jun 28, 2004 at 4:08 pm
    Thanks for your comments. It is a good idea. ultimately I was thinking of
    using the array. Since I am a new bee to this, while writing small programs
    I am trying to learn different aspects of the same function. Which I believe
    will be good for me in the long run. and in return I ll be able to
    contribute when I am ready.
    This was just a snippet of code for people to look at and evaluate logic and
    comment, not on the whole program and programming semantics. I do not like
    to waste list members valuable time on reading the whole code where it is
    not necessary.

    Thanks

    -----Original Message-----
    From: Gunnar Hjalmarsson
    Sent: Monday, June 28, 2004 11:55 AM
    To: beginners@perl.org
    Subject: Re: string seperated by multiple spaces


    Naser Ali wrote:
    Any suggestions on what am I doing wrong..?
    Why do you want a scalar variable for each value? Why not using an
    array instead?

    And you seem not to be using strictures and warnings.

    Others have helped you with the pattern passed to split().

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl

    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>
  • Naser Ali at Jun 28, 2004 at 4:16 pm
    Below is the actual code. This is just the preliminary code to test the
    logic, it is not final yet, therefore, I am not using "Warnings", "Strict"
    or for that matter anything else. Also I am slurrping the whole file, and I
    know I do not have to, but alternate ways, I ll decide later.

    Thanks

    -------------------------------------------------------------------------
    open(TFILE, "file.txt");
    @first=<TFILE>;
    close (TFILE);


    for ($i=0; $i <= $#first; $i++) {

    $Avg=$first[$i];
    chomp($Avg);
    ($label,$TD,$YT,$M,$L,$Y,$W)= split (/\s+/,$Avg);
    print "$label,$TD,$YT,$M,$L,$Y,$W\n";
    }
    ---------------------------------------------------------------------------


    -----Original Message-----
    From: Gunnar Hjalmarsson
    Sent: Monday, June 28, 2004 12:01 PM
    To: beginners@perl.org
    Subject: Re: string seperated by multiple spaces


    Naser Ali wrote:
    I tried with, after removing "i"

    " split ' ' " and " split (/\s+/,$Avg) " as well, but no success
    In that case there is a problem also with a part of your code that you
    did not show us.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl

    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>
  • James Edward Gray II at Jun 28, 2004 at 4:28 pm

    On Jun 28, 2004, at 11:15 AM, Naser Ali wrote:

    Below is the actual code. This is just the preliminary code to test the
    logic, it is not final yet, therefore, I am not using "Warnings",
    "Strict"
    or for that matter anything else.
    It's easy to make excuses, harder to do the right thing. Help us help
    you. I've seen enough of your posts, these lessons should be learned
    by now. You START with warnings and strict, when they can help you
    most.

    I bet you would be getting warnings right now, if only you would turn
    them on. Then, if you followed them, you might just solve your own
    problem.
    Also I am slurrping the whole file, and I know I do not have to, but
    alternate ways, I ll decide later.
    Why? Why code it twice? Two different techniques. Just use the right
    one, and stop hindering your own growth as a programmer.
    -----------------------------------------------------------------------
    --
    open(TFILE, "file.txt");
    ... or die "..."; # MUST test success
    @first=<TFILE>;
    Not needed, and you know it.
    close (TFILE);


    for ($i=0; $i <= $#first; $i++) {
    In Perl, we write that:

    for my $i (0..$#first) {

    Of course, you aren't even using indexes, so better is:

    foreach (@first) {
    $Avg=$first[$i]; Why?
    chomp($Avg);
    ($label,$TD,$YT,$M,$L,$Y,$W)= split (/\s+/,$Avg);
    ... split ' ', $Avg;

    If it's not working, $Avg doesn't contain what you think it does. Add
    a print statement before to prove it.
    print "$label,$TD,$YT,$M,$L,$Y,$W\n";
    }
    James
  • Michelle Rogers at Jun 28, 2004 at 4:32 pm
    wow..somebody woke up on the wrong side of bed, this morning...
    shesh...
    Michelle Rogers
    ----- Original Message -----
    From: "James Edward Gray II" <james@grayproductions.net>
    To: "Naser Ali" <Ali.Naser@irs.gov>
    Cc: "Perl Beginners" <beginners@perl.org>
    Sent: Monday, June 28, 2004 12:28 PM
    Subject: Re: string seperated by multiple spaces

    On Jun 28, 2004, at 11:15 AM, Naser Ali wrote:

    Below is the actual code. This is just the preliminary code to test the
    logic, it is not final yet, therefore, I am not using "Warnings",
    "Strict"
    or for that matter anything else.
    It's easy to make excuses, harder to do the right thing. Help us help
    you. I've seen enough of your posts, these lessons should be learned
    by now. You START with warnings and strict, when they can help you
    most.

    I bet you would be getting warnings right now, if only you would turn
    them on. Then, if you followed them, you might just solve your own
    problem.
    Also I am slurrping the whole file, and I know I do not have to, but
    alternate ways, I ll decide later.
    Why? Why code it twice? Two different techniques. Just use the right
    one, and stop hindering your own growth as a programmer.
    -----------------------------------------------------------------------
    --
    open(TFILE, "file.txt");
    ... or die "..."; # MUST test success
    @first=<TFILE>;
    Not needed, and you know it.
    close (TFILE);


    for ($i=0; $i <= $#first; $i++) {
    In Perl, we write that:

    for my $i (0..$#first) {

    Of course, you aren't even using indexes, so better is:

    foreach (@first) {
    $Avg=$first[$i]; Why?
    chomp($Avg);
    ($label,$TD,$YT,$M,$L,$Y,$W)= split (/\s+/,$Avg);
    ... split ' ', $Avg;

    If it's not working, $Avg doesn't contain what you think it does. Add
    a print statement before to prove it.
    print "$label,$TD,$YT,$M,$L,$Y,$W\n";
    }
    James


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>
  • James Edward Gray II at Jun 28, 2004 at 4:45 pm

    On Jun 28, 2004, at 11:32 AM, Michelle Rogers wrote:

    wow..somebody woke up on the wrong side of bed, this morning...
    I wish I could say I was sorry. ;)

    You think whatever you want of me, but I'm not wrong. I've tried
    telling the person who started this thread before. Now I'm trying
    something else.

    I really do want to help. That's why I'm here and that's why I said
    what I said.

    It's a good lesson to all, I think. Asking us to volunteer our time to
    read your junk code is not a good way to make friends.

    James
  • Gunnar Hjalmarsson at Jun 28, 2004 at 4:34 pm

    Naser Ali wrote:
    Below is the actual code. This is just the preliminary code to test
    the logic, it is not final yet, therefore, I am not using
    "Warnings", "Strict" or for that matter anything else.
    That reasoning is so very, very *wrong*. Strictures and warnings are
    not to be added when a program is finished. On the contrary, it's most
    useful when developing the program in order to have Perl instantly let
    you know about typos and other errors.
    open(TFILE, "file.txt");
    open TFILE, 'file.txt' or die "Couldn't open file for reading $!";

    (I can't locate any obvious errors in your code.)

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
  • Charles K. Clarkson at Jun 28, 2004 at 4:39 pm
    From: Naser Ali wrote:

    : Below is the actual code. This is just the preliminary code
    : to test the logic, it is not final yet, therefore, I am not
    : using "Warnings", "Strict" or for that matter anything else.

    Use strict and warnings from the very beginning. Don't
    wait while you're testing. I use them always. Even for the
    itty bitty scripts.


    : Also I am slurrping the whole file, and I know I do not have
    : to, but alternate ways, I ll decide later.

    There's nothing wrong with pulling in the whole file
    at once if you are certain the file size will remain
    small.


    : open(TFILE, "file.txt");
    : @first=<TFILE>;
    : close (TFILE);
    :
    :
    : for ($i=0; $i <= $#first; $i++) {
    :
    : $Avg=$first[$i];
    : chomp($Avg);
    : ($label,$TD,$YT,$M,$L,$Y,$W)= split (/\s+/,$Avg);
    : print "$label,$TD,$YT,$M,$L,$Y,$W\n";
    : }

    That works fine. Perhaps file.txt is not opening or
    contains something you don't expect. Try this:


    use strict;
    use warnings;


    my $file = 'file.txt';
    open FH, $file or die "Cannot open $file: $!";
    my @averages = <FH>;
    close FH;

    foreach my $average ( @averages ) {

    chomp $average;

    my @fields = split ' ', $average;

    print " Bad line --> $average " unless @fields == 7;

    print join( ', ', @fields ), "\n";
    }

    __END__


    HTH,

    Charles K. Clarkson
    --
    Mobile Homes Specialist
    254 968-8328
  • MCMULLIN, NANCY at Jun 28, 2004 at 4:38 pm
    After all, I thought the name of this group was Perl BEGINNERS...

    -----Original Message-----
    From: Michelle Rogers
    Sent: Monday, June 28, 2004 10:33 AM
    To: James Edward Gray II; Naser Ali
    Cc: Perl Beginners
    Subject: Re: string seperated by multiple spaces


    wow..somebody woke up on the wrong side of bed, this morning...
    shesh...
    Michelle Rogers
    ----- Original Message -----
    From: "James Edward Gray II" <james@grayproductions.net>
    To: "Naser Ali" <Ali.Naser@irs.gov>
    Cc: "Perl Beginners" <beginners@perl.org>
    Sent: Monday, June 28, 2004 12:28 PM
    Subject: Re: string seperated by multiple spaces

    On Jun 28, 2004, at 11:15 AM, Naser Ali wrote:

    Below is the actual code. This is just the preliminary code to test the
    logic, it is not final yet, therefore, I am not using "Warnings",
    "Strict"
    or for that matter anything else.
    It's easy to make excuses, harder to do the right thing. Help us help
    you. I've seen enough of your posts, these lessons should be learned
    by now. You START with warnings and strict, when they can help you
    most.

    I bet you would be getting warnings right now, if only you would turn
    them on. Then, if you followed them, you might just solve your own
    problem.
    Also I am slurrping the whole file, and I know I do not have to, but
    alternate ways, I ll decide later.
    Why? Why code it twice? Two different techniques. Just use the right
    one, and stop hindering your own growth as a programmer.
    -----------------------------------------------------------------------
    --
    open(TFILE, "file.txt");
    ... or die "..."; # MUST test success
    @first=<TFILE>;
    Not needed, and you know it.
    close (TFILE);


    for ($i=0; $i <= $#first; $i++) {
    In Perl, we write that:

    for my $i (0..$#first) {

    Of course, you aren't even using indexes, so better is:

    foreach (@first) {
    $Avg=$first[$i]; Why?
    chomp($Avg);
    ($label,$TD,$YT,$M,$L,$Y,$W)= split (/\s+/,$Avg);
    ... split ' ', $Avg;

    If it's not working, $Avg doesn't contain what you think it does. Add
    a print statement before to prove it.
    print "$label,$TD,$YT,$M,$L,$Y,$W\n";
    }
    James


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>

    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>
  • Michelle Rogers at Jun 28, 2004 at 4:45 pm
    *grins at you* yes..yes...that's what it says...unless it's false
    advertising
    Michelle Rogers
    ----- Original Message -----
    From: "MCMULLIN, NANCY" <NANCY.MCMULLIN@DFAS.MIL>
    To: "Michelle Rogers" <michellerogers@bellsouth.net>; "James Edward Gray II"
    <james@grayproductions.net>; "Naser Ali" <Ali.Naser@irs.gov>
    Cc: "Perl Beginners" <beginners@perl.org>
    Sent: Monday, June 28, 2004 12:37 PM
    Subject: RE: string seperated by multiple spaces



    After all, I thought the name of this group was Perl BEGINNERS...

    -----Original Message-----
    From: Michelle Rogers
    Sent: Monday, June 28, 2004 10:33 AM
    To: James Edward Gray II; Naser Ali
    Cc: Perl Beginners
    Subject: Re: string seperated by multiple spaces


    wow..somebody woke up on the wrong side of bed, this morning...
    shesh...
    Michelle Rogers
    ----- Original Message -----
    From: "James Edward Gray II" <james@grayproductions.net>
    To: "Naser Ali" <Ali.Naser@irs.gov>
    Cc: "Perl Beginners" <beginners@perl.org>
    Sent: Monday, June 28, 2004 12:28 PM
    Subject: Re: string seperated by multiple spaces

    On Jun 28, 2004, at 11:15 AM, Naser Ali wrote:

    Below is the actual code. This is just the preliminary code to test the
    logic, it is not final yet, therefore, I am not using "Warnings",
    "Strict"
    or for that matter anything else.
    It's easy to make excuses, harder to do the right thing. Help us help
    you. I've seen enough of your posts, these lessons should be learned
    by now. You START with warnings and strict, when they can help you
    most.

    I bet you would be getting warnings right now, if only you would turn
    them on. Then, if you followed them, you might just solve your own
    problem.
    Also I am slurrping the whole file, and I know I do not have to, but
    alternate ways, I ll decide later.
    Why? Why code it twice? Two different techniques. Just use the right
    one, and stop hindering your own growth as a programmer.
    -----------------------------------------------------------------------
    --
    open(TFILE, "file.txt");
    ... or die "..."; # MUST test success
    @first=<TFILE>;
    Not needed, and you know it.
    close (TFILE);


    for ($i=0; $i <= $#first; $i++) {
    In Perl, we write that:

    for my $i (0..$#first) {

    Of course, you aren't even using indexes, so better is:

    foreach (@first) {
    $Avg=$first[$i]; Why?
    chomp($Avg);
    ($label,$TD,$YT,$M,$L,$Y,$W)= split (/\s+/,$Avg);
    ... split ' ', $Avg;

    If it's not working, $Avg doesn't contain what you think it does. Add
    a print statement before to prove it.
    print "$label,$TD,$YT,$M,$L,$Y,$W\n";
    }
    James


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>

    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>



    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>
  • James Edward Gray II at Jun 28, 2004 at 4:47 pm

    On Jun 28, 2004, at 11:37 AM, MCMULLIN, NANCY wrote:

    After all, I thought the name of this group was Perl BEGINNERS...
    Sure is. And the FIRST thing beginners need to learn is to add strict
    and warnings to help them learn. It also helps us read your code,
    which can only be good for you.

    James
  • Michelle Rogers at Jun 28, 2004 at 4:57 pm
    The point is...if you're wanting to help beginners....be nice....don't jump
    down their throats....I'd prefer not to have that type of help. Use Charles
    K. Clarkson, as an example. He said the exact same thing, but said it in a
    way that it should be said to beginners. I guess I'm taking it upon myself
    to say this because I don't intend to stay in this group (and may have
    decided not to this morning, after that message, if I hadn't already decided
    that)...I've decided to use euphoria instead of perl for what i'm doing.
    And, i guess i'm thinking that someone needs to protect the "young and
    innocent". That person that you just jumped down their throat may have
    been the person who was going to code the greatest software the world has
    ever seen.....but the way that was handled...they may give up and never try
    again.

    Golden Rule: Do to others, as you would want them to do to you.
    And while you might argue that you would want people to point out things to
    correct, if it were you, I'd daresay that you also would want them to do it
    nicely.

    Michelle Rogers
    ----- Original Message -----
    From: "James Edward Gray II" <james@grayproductions.net>
    To: "MCMULLIN, NANCY" <NANCY.MCMULLIN@DFAS.MIL>
    Cc: "Perl Beginners" <beginners@perl.org>
    Sent: Monday, June 28, 2004 12:47 PM
    Subject: Re: string seperated by multiple spaces

    On Jun 28, 2004, at 11:37 AM, MCMULLIN, NANCY wrote:

    After all, I thought the name of this group was Perl BEGINNERS...
    Sure is. And the FIRST thing beginners need to learn is to add strict
    and warnings to help them learn. It also helps us read your code,
    which can only be good for you.

    James


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>
  • Gunnar Hjalmarsson at Jun 28, 2004 at 5:17 pm

    Michelle Rogers wrote:
    The point is...if you're wanting to help beginners....be
    nice....don't jump down their throats....I'd prefer not to have
    that type of help. Use Charles K. Clarkson, as an example. He
    said the exact same thing, but said it in a way that it should be
    said to beginners.
    'beginners' ne 'children'

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
  • John W. Krahn at Jun 28, 2004 at 6:39 pm

    Michelle Rogers wrote:

    The point is...if you're wanting to help beginners....be nice....don't jump
    down their throats....I'd prefer not to have that type of help. Use Charles
    K. Clarkson, as an example. He said the exact same thing, but said it in a
    way that it should be said to beginners. I guess I'm taking it upon myself
    to say this because I don't intend to stay in this group (and may have
    decided not to this morning, after that message, if I hadn't already decided
    that)...I've decided to use euphoria instead of perl for what i'm doing.
    And, i guess i'm thinking that someone needs to protect the "young and
    innocent". That person that you just jumped down their throat may have
    been the person who was going to code the greatest software the world has
    ever seen.....but the way that was handled...they may give up and never try
    again.

    Golden Rule: Do to others, as you would want them to do to you.
    And while you might argue that you would want people to point out things to
    correct, if it were you, I'd daresay that you also would want them to do it
    nicely.
    Ah yes, good advice. I try to set a good example by not TOP POSTING but
    some people just don't "GET IT" (whatever IT is.) Most times it is very
    hard to teach people over a text only medium especially when you are
    trying to teach people who don't know what they don't know. :-)


    John
    --
    use Perl;
    program
    fulfillment
  • John W. Krahn at Jun 28, 2004 at 9:54 pm

    Michelle Rogers wrote:

    The point is...if you're wanting to help beginners....be nice....don't jump
    down their throats....I'd prefer not to have that type of help. Use Charles
    K. Clarkson, as an example. He said the exact same thing, but said it in a
    way that it should be said to beginners. I guess I'm taking it upon myself
    to say this because I don't intend to stay in this group (and may have
    decided not to this morning, after that message, if I hadn't already decided
    that)...I've decided to use euphoria instead of perl for what i'm doing.
    And, i guess i'm thinking that someone needs to protect the "young and
    innocent". That person that you just jumped down their throat may have
    been the person who was going to code the greatest software the world has
    ever seen.....but the way that was handled...they may give up and never try
    again.

    Golden Rule: Do to others, as you would want them to do to you.
    And while you might argue that you would want people to point out things to
    correct, if it were you, I'd daresay that you also would want them to do it
    nicely.
    Ah yes, good advice. I try to set a good example by not TOP POSTING but
    some people just don't "GET IT" (whatever IT is.) Most times it is very
    hard to teach people over a text only medium especially when you are
    trying to teach people who don't know what they don't know. :-)


    John
    --
    use Perl;
    program
    fulfillment
  • Charles K. Clarkson at Jun 28, 2004 at 5:10 pm
    MCMULLIN, NANCY wrote:

    : After all, I thought the name of this group was Perl BEGINNERS...

    So it's not Perl Beginners for TOP POSTERS, Huh?

    Imagine that. :)


    HTH,

    Charles K. Clarkson
    --
    Mobile Homes Specialist
    254 968-8328
  • MCMULLIN, NANCY at Jun 28, 2004 at 4:53 pm
    James - we do appreciate your time and help. My hope is that because of your help, and our own training efforts, eventually we won't be sending you "junk code". ;-)

    -----Original Message-----
    From: James Edward Gray II
    Sent: Monday, June 28, 2004 10:45 AM
    To: Michelle Rogers
    Cc: Perl Beginners
    Subject: Re: string seperated by multiple spaces

    On Jun 28, 2004, at 11:32 AM, Michelle Rogers wrote:

    wow..somebody woke up on the wrong side of bed, this morning...
    I wish I could say I was sorry. ;)

    You think whatever you want of me, but I'm not wrong. I've tried
    telling the person who started this thread before. Now I'm trying
    something else.

    I really do want to help. That's why I'm here and that's why I said
    what I said.

    It's a good lesson to all, I think. Asking us to volunteer our time to
    read your junk code is not a good way to make friends.

    James


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>
  • Naser Ali at Jun 28, 2004 at 4:55 pm
    Thanks Charles,

    Now your polite comments on using warnings make me think and as well as
    guilty. Also emphasizes on going an extra mile at times helps save time.
    Point well taken,

    But on the other hand there are people on the list like "Mr. James Edward
    Gray II" has some ego problems. No body asked you to answer my question. if
    you really think beginners like me, for whom this list was created in the
    first place, are not worthy of your expertise and knowledge, then please by
    all means spare us from your wisdom and as well as criticism. You must bare
    mind that different people think differntly and will have different approach
    which must not be mistaken by polity and lazyness without knowing for sure.

    With all due respect, if you can't, then do not help. The world will survive
    without your help.

    Thanks

    -----Original Message-----
    From: Charles K. Clarkson
    Sent: Monday, June 28, 2004 12:39 PM
    To: 'Naser Ali'; beginners@perl.org
    Subject: RE: string seperated by multiple spaces


    From: Naser Ali wrote:

    : Below is the actual code. This is just the preliminary code
    : to test the logic, it is not final yet, therefore, I am not
    : using "Warnings", "Strict" or for that matter anything else.

    Use strict and warnings from the very beginning. Don't
    wait while you're testing. I use them always. Even for the
    itty bitty scripts.


    : Also I am slurrping the whole file, and I know I do not have
    : to, but alternate ways, I ll decide later.

    There's nothing wrong with pulling in the whole file
    at once if you are certain the file size will remain
    small.


    : open(TFILE, "file.txt");
    : @first=<TFILE>;
    : close (TFILE);
    :
    :
    : for ($i=0; $i <= $#first; $i++) {
    :
    : $Avg=$first[$i];
    : chomp($Avg);
    : ($label,$TD,$YT,$M,$L,$Y,$W)= split (/\s+/,$Avg);
    : print "$label,$TD,$YT,$M,$L,$Y,$W\n";
    : }

    That works fine. Perhaps file.txt is not opening or contains something
    you don't expect. Try this:


    use strict;
    use warnings;


    my $file = 'file.txt';
    open FH, $file or die "Cannot open $file: $!";
    my @averages = <FH>;
    close FH;

    foreach my $average ( @averages ) {

    chomp $average;

    my @fields = split ' ', $average;

    print " Bad line --> $average " unless @fields == 7;

    print join( ', ', @fields ), "\n";
    }

    __END__


    HTH,

    Charles K. Clarkson
    --
    Mobile Homes Specialist
    254 968-8328
  • Michelle Rogers at Jun 28, 2004 at 5:02 pm
    <quote>
    With all due respect, if you can't, then do not help. The world will survive
    without your help.
    <end quote>


    That's my point. If help isn't given cheerfully, it does more harm than
    good.
  • James Edward Gray II at Jun 28, 2004 at 5:05 pm

    On Jun 28, 2004, at 11:55 AM, Naser Ali wrote:

    But on the other hand there are people on the list like "Mr. James
    Edward
    Gray II" has some ego problems. No body asked you to answer my
    question. if
    you really think beginners like me, for whom this list was created in
    the
    first place, are not worthy of your expertise and knowledge, then
    please by
    all means spare us from your wisdom and as well as criticism. You must
    bare
    mind that different people think differntly and will have different
    approach
    which must not be mistaken by polity and lazyness without knowing for
    sure.

    With all due respect, if you can't, then do not help. The world will
    survive
    without your help.
    I'm sorry my response offended you. I'll refrain from answering your
    future questions, as requested.

    James
  • Charles K. Clarkson at Jun 28, 2004 at 5:08 pm
    Naser Ali wrote:

    : Now your polite comments on using warnings make me think
    : and as well as guilty. Also emphasizes on going an extra
    : mile at times helps save time. Point well taken,
    :
    : But on the other hand there are people on the list like
    : "Mr. James Edward Gray II" has some ego problems. No body
    : asked you to answer my question. if you really think
    : beginners like me, for whom this list was created in the
    : first place, are not worthy of your expertise and
    : knowledge, then please by all means spare us from your
    : wisdom and as well as criticism. You must bare mind that
    : different people think differntly and will have different
    : approach which must not be mistaken by polity and
    : lazyness without knowing for sure.
    :
    : With all due respect, if you can't, then do not help. The
    : world will survive without your help.

    Ali, I appreciate the praise but I think James used a
    acceptable approach in his reply.

    If you go back to 6/16 when you asked about "how to sort
    certain pattern from a file", James answered your question
    and explained very patiently that you needed to add strict
    and warnings and that you needed to verify I/O operations.

    Some beginners don't take our advice. It is now up to
    us to try some other methods to drive home those points.
    Learning is not always easy and teaching sometimes
    involves sticks as well as carrots.

    James realized that you didn't follow his advice from
    the earlier post and was trying a different method to help
    you. I value James' advice and I hope you will also in the
    future. Be thankful that someone is willing to go out on
    that limb to help you. Very few people will.

    HTH,

    Charles K. Clarkson
    --
    Mobile Homes Specialist
    254 968-8328
  • Gunnar Hjalmarsson at Jun 28, 2004 at 5:10 pm

    Naser Ali wrote:
    But on the other hand there are people on the list like "Mr. James
    Edward Gray II" has some ego problems. No body asked you to answer
    my question. if you really think beginners like me, for whom this
    list was created in the first place, are not worthy of your
    expertise and knowledge, then please by all means spare us from
    your wisdom and as well as criticism.
    Please spare us from your whining!!

    Beginners list or not, bear in mind that those who answer questions
    here are volunteers. It's bad manners to deliberately refrain from
    applying practices that would have made it easier to help (or that
    might have led to your solving the problem without asking).
    You must bare mind that different people think differntly and will
    have different approach
    But you are not writing your own programming language, are you? Those
    who wrote Perl thought along certain lines, and we who are using the
    program must adapt whether we like it or not.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
  • Wiggins d Anconia at Jun 28, 2004 at 5:10 pm

    Thanks Charles,

    Now your polite comments on using warnings make me think and as well as
    guilty. Also emphasizes on going an extra mile at times helps save time.
    Point well taken,

    But on the other hand there are people on the list like "Mr. James Edward
    Gray II" has some ego problems. No body asked you to answer my question.
    Careful James has answered a lot of questions and done a very good job
    of it, and these postings are archived.


    if
    you really think beginners like me, for whom this list was created in the
    first place, are not worthy of your expertise and knowledge, then please by
    all means spare us from your wisdom and as well as criticism. You must bare
    mind that different people think differntly and will have different approach
    which must not be mistaken by polity and lazyness without knowing for sure.
    With all due respect, if you can't, then do not help. The world will survive
    without your help.
    He did help, and his position was supported by similar statements from
    another poster. You yourself also stated you didn't want to waste other
    poster's time, but not turning on strict/warnings is a direct
    contradiction of that. He also mentioned that you had been around a
    while and should no better, I can't attest one way or another, so many
    names are just fly bys, but you should take that as a complement and a
    hint...

    I will admit this is a beginners list, but if you thought James'
    comments were harsh you need to grow a much, much tougher skin before
    venturing out on to the rest of the internet. Good thing Randal wasn't
    around ;-)....

    http://danconia.org
    -----Original Message-----
    From: Charles K. Clarkson
    Sent: Monday, June 28, 2004 12:39 PM
    To: 'Naser Ali'; beginners@perl.org
    Subject: RE: string seperated by multiple spaces


    From: Naser Ali wrote:

    : Below is the actual code. This is just the preliminary code
    : to test the logic, it is not final yet, therefore, I am not
    : using "Warnings", "Strict" or for that matter anything else.

    Use strict and warnings from the very beginning. Don't
    wait while you're testing. I use them always. Even for the
    itty bitty scripts.


    : Also I am slurrping the whole file, and I know I do not have
    : to, but alternate ways, I ll decide later.

    There's nothing wrong with pulling in the whole file
    at once if you are certain the file size will remain
    small.


    : open(TFILE, "file.txt");
    : @first=<TFILE>;
    : close (TFILE);
    :
    :
    : for ($i=0; $i <= $#first; $i++) {
    :
    : $Avg=$first[$i];
    : chomp($Avg);
    : ($label,$TD,$YT,$M,$L,$Y,$W)= split (/\s+/,$Avg);
    : print "$label,$TD,$YT,$M,$L,$Y,$W\n";
    : }

    That works fine. Perhaps file.txt is not opening or contains something
    you don't expect. Try this:


    use strict;
    use warnings;


    my $file = 'file.txt';
    open FH, $file or die "Cannot open $file: $!";
    my @averages = <FH>;
    close FH;

    foreach my $average ( @averages ) {

    chomp $average;

    my @fields = split ' ', $average;

    print " Bad line --> $average " unless @fields == 7;

    print join( ', ', @fields ), "\n";
    }

    __END__


    HTH,

    Charles K. Clarkson
    --
    Mobile Homes Specialist
    254 968-8328


  • Naser Ali at Jun 28, 2004 at 5:47 pm
    Please accept my Apollgies.
    Your response did offend me, but I did not let it. So why did I write back
    in an offensive and offending way..? just to make a point that your approach
    was not right just like mine in responding to you. Just wanted to show that
    jumping to conclusion and pre-judging is not a good practice. it gets the
    best of us.
    I agree with you 100%, and also appreciate your help in the past and will
    always do, but will not allow anyone to disrespect and acuse. Now just think
    for a second on the wording below,
    make excuses,
    ...Help us help you....
    I've seen enough of your posts, ...........
    by now.
    and stop hindering your own growth as a programmer.
    but you must agree with me that while asking a question about a regex or
    just simple logic should not require to show the whole thing al the time,
    which in turn saves others time. Even from my first post, there were pleanty
    of emails just emphasizing on using "warnings" and simple perl programming
    practices and the point was well taken then too. But one has to keep in mind
    that every body has different style. I have worked on so many different
    projects and nobody had followed the same coding practices.
    Even from previous posts, this kind of jargon has taken so much of every
    body's time, at least that is how I thought

    I guess I ll just stop here.

    Best regards and my apollgies to every one who felt offended by my post.


    -----Original Message-----
    From: James Edward Gray II
    Sent: Monday, June 28, 2004 1:05 PM
    To: Naser Ali
    Cc: Perl Beginners
    Subject: Re: string seperated by multiple spaces

    On Jun 28, 2004, at 11:55 AM, Naser Ali wrote:

    But on the other hand there are people on the list like "Mr. James
    Edward
    Gray II" has some ego problems. No body asked you to answer my
    question. if
    you really think beginners like me, for whom this list was created in
    the
    first place, are not worthy of your expertise and knowledge, then
    please by
    all means spare us from your wisdom and as well as criticism. You must
    bare
    mind that different people think differntly and will have different
    approach
    which must not be mistaken by polity and lazyness without knowing for
    sure.

    With all due respect, if you can't, then do not help. The world will
    survive
    without your help.
    I'm sorry my response offended you. I'll refrain from answering your
    future questions, as requested.

    James


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>
  • Bob Showalter at Jun 28, 2004 at 6:21 pm

    Naser Ali wrote:
    I used "\s*" in split, so I do not have worry about counting the
    spaces or tabs between each field
    I noticed something in the OP that didn't really get addressed:

    \s* will match an empty string, which will split into a list of single
    characters.

    $ perl -le 'print for split /\s*/, "foo bar"'
    f
    o
    o
    b
    a
    r

    You want \s+, or even better ' ' (there is a slight difference between the
    two)

    $ perl -le 'print for split q[ ], "foo bar"'
    foo
    bar

    perldoc -f split gives all the gory details.

    HTH

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedJun 28, '04 at 3:26p
activeJun 28, '04 at 9:54p
posts31
users10
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase