Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Comparing two arrays

Expand Messages
  • Charles K. Clarkson
    Gregory Fox ... Just one. What is the question?
    Message 1 of 4 , Dec 3, 2001
    • 0 Attachment
      "Gregory Fox" <greg@...>

      : Here's one:
      :
      : I have 2 arrays:
      :
      : Before modifications:
      : 1|BP-01|26|571.74||Betty Boop - Casablanca|||||||1|21.99|HollyBoop|
      : 2|PC-01|70|1120.98||Pepsi Ice Cold! Delicious|||||||1|10.99|Pepsi-
      : Cola Metal Signs|
      : 3|PC-02|32|1120.98||Pepsi 6 Pack|||||||1|10.99|Pepsi-Cola Metal Signs|
      :
      :
      : After modifications:
      : 1|BP-01|101|1395.73||Betty Boop - Casablanca|||||||1|10.99|HollyBoop|
      : 2|PC-01|100|1868.3||Pepsi Ice Cold! Delicious|||||||1|10.99|Pepsi-
      : Cola Metal Signs|
      : 3|PC-02|32|1120.98||Pepsi 6 Pack|||||||1|10.99|Pepsi-Cola Metal Signs|
      :
      : However, here is the twist. More than one item maybe modified at
      : once. So we need to loop back through and update additional items.
      :
      : For example, the After array could look like this:
      :
      : 1|BP-01|101|1395.73||Betty Boop - Casablanca|||||||1|10.99|HollyBoop|
      : 2|PC-01|200|1868.3||Pepsi Ice Cold! Delicious|||||||1|5.99|Pepsi-Cola
      : Metal Signs|
      : 3|PC-02|32|1120.98||Pepsi 6 Pack|||||||1|10.99|Pepsi-Cola Metal Signs|
      :
      : Any ideas?

      Just one.
      What is the question?
    • Eric Via
      Greetings Perl friends from Texas! I m ALMOST to the point where I can break away from regular ol Korn shell scripts and do what I need to do in Perl at work.
      Message 2 of 4 , Dec 3, 2001
      • 0 Attachment
        Greetings Perl friends from Texas!

        I'm ALMOST to the point where I can break away from regular ol'
        Korn shell scripts and do what I need to do in Perl at work.

        And it's a good feeling - and I owe a lot of my education to you
        kind and knowledgeable souls.

        However there's two commands which I have yet to figure out how to
        do nicely in Perl - commands I use in shell scripts quite often -
        favorite commands. The first I used in shell scripts when I cut out
        fields and I want to add them up easily, and uses AWK:

        summary=`awk '{sum=sum+$1;printf("%d\n", sum)}' < list.txt | tail -1`

        A simple command yes, but I like to use it - is there an easy way
        to sum up a column of numbers from a file in Perl - I can use substr
        to pull them out and write them to a file, and then I'd like to add
        them up.

        My second favorite command I find I use a lot is simply to count up
        lines in a file, like using "wc -l" - except for this command returns
        ONLY the count, which I like, it uses SED:

        howmany=`sed -n '$=' list.txt

        Is there an easy way to do the same thing in Perl - to just with
        one line of code count up a list of something?

        If any of you kind people have any insight or suggestions I'd be
        eternally grateful!

        Eric



        --
        ------------------------------------
        Eric Via
        coolhand.luke@...
        My home page: http://web2.airmail.net/ericvia/ericpage.html
        (Buddhism, VW New Beetle, Mercedes, Spam, Jokes, D.B. Cooper,
        Trains, & more!)
        ------------------------------------
        A flower falls, even though we love it; and a weed grows, even though
        we do not love it.
        -Dogen
      • ramprasad@netcore.co.in
        If u want the total no if lines in STDIN use @lines= ;print scalar(@lines); else open $ARGV[0] as a FILE and do the same ... to ... -1` ... way ... up
        Message 3 of 4 , Dec 3, 2001
        • 0 Attachment
          If u want the total no if lines in STDIN use
          @lines=<STDIN>;print scalar(@lines);

          else open $ARGV[0] as a FILE and do the same



          --- In perl-beginner@y..., Eric Via <coolhand.luke@v...> wrote:
          > Greetings Perl friends from Texas!
          >
          > I'm ALMOST to the point where I can break away from regular ol'
          > Korn shell scripts and do what I need to do in Perl at work.
          >
          > And it's a good feeling - and I owe a lot of my education to you
          > kind and knowledgeable souls.
          >
          > However there's two commands which I have yet to figure out how
          to
          > do nicely in Perl - commands I use in shell scripts quite often -
          > favorite commands. The first I used in shell scripts when I cut out
          > fields and I want to add them up easily, and uses AWK:
          >
          > summary=`awk '{sum=sum+$1;printf("%d\n", sum)}' < list.txt | tail
          -1`
          >
          > A simple command yes, but I like to use it - is there an easy
          way
          > to sum up a column of numbers from a file in Perl - I can use substr
          > to pull them out and write them to a file, and then I'd like to add
          > them up.
          >
          > My second favorite command I find I use a lot is simply to count
          up
          > lines in a file, like using "wc -l" - except for this command
          returns
          > ONLY the count, which I like, it uses SED:
          >
          > howmany=`sed -n '$=' list.txt
          >
          > Is there an easy way to do the same thing in Perl - to just with
          > one line of code count up a list of something?
          >
          > If any of you kind people have any insight or suggestions I'd be
          > eternally grateful!
          >
          > Eric
          >
          >
          >
          > --
          > ------------------------------------
          > Eric Via
          > coolhand.luke@v...
          > My home page: http://web2.airmail.net/ericvia/ericpage.html
          > (Buddhism, VW New Beetle, Mercedes, Spam, Jokes, D.B. Cooper,
          > Trains, & more!)
          > ------------------------------------
          > A flower falls, even though we love it; and a weed grows, even
          though
          > we do not love it.
          > -Dogen
        • Eric Via
          ... VERY nice!! I ll try this! THANK YOU so much!! Eric -- ... Eric Via coolhand.luke@verizon.net My home page: http://web2.airmail.net/ericvia/ericpage.html
          Message 4 of 4 , Dec 3, 2001
          • 0 Attachment
            On 12/4/01, at around 5:55 AM +0000, ramprasad@... said: :

            >If u want the total no if lines in STDIN use
            >@lines=<STDIN>;print scalar(@lines);
            >
            >else open $ARGV[0] as a FILE and do the same

            VERY nice!! I'll try this! THANK YOU so much!!


            Eric
            --
            ------------------------------------
            Eric Via
            coolhand.luke@...
            My home page: http://web2.airmail.net/ericvia/ericpage.html
            (Buddhism, VW New Beetle, Mercedes, Spam, Jokes, D.B. Cooper,
            Trains, & more!)
            ------------------------------------
            A flower falls, even though we love it; and a weed grows, even though
            we do not love it.
            -Dogen
          Your message has been successfully submitted and would be delivered to recipients shortly.