Where to hitch the <<EOF to plaster input file?

Discussion in 'Perl Misc' started by Dan Jacobson, Jul 26, 2003.

  1. Dan Jacobson

    Dan Jacobson Guest

    Where do I hitch the <<EOF so I can plaster my input file right into
    this source file? Yes, saw man perlop. Yes, I am prepared to give up
    -anl if that's the price to pay.

    #!/usr/bin/perl -anlw
    #Input: each line consists of seconds per rotation of electric meter disk followed by
    #a note of what appliances were on at the time.
    #Output: total watts, appliance list. The Kh factor is written on the meter.
    #Reference: http://www.earth.uni.edu/EECP/elem/mod2_math.html
    BEGIN { $Kh = 7.2 };
    unless (/^[^#]/) { next }
    $p = 3600 * $Kh / $F[0];
    shift @F;
    print int($p), "\t@F";
    Dan Jacobson, Jul 26, 2003
    #1
    1. Advertising

  2. Dan Jacobson

    Eric Amick Guest

    On Sat, 26 Jul 2003 12:45:25 +0800, Dan Jacobson <>
    wrote:

    >Where do I hitch the <<EOF so I can plaster my input file right into
    >this source file? Yes, saw man perlop. Yes, I am prepared to give up
    >-anl if that's the price to pay.


    You'll have to give up the -anl; <<EOF can't put data into a filehandle.
    Despite its resemblance to shell here-documents, it doesn't work the
    same.

    >#!/usr/bin/perl -anlw
    >#Input: each line consists of seconds per rotation of electric meter disk followed by
    >#a note of what appliances were on at the time.
    >#Output: total watts, appliance list. The Kh factor is written on the meter.
    >#Reference: http://www.earth.uni.edu/EECP/elem/mod2_math.html
    >BEGIN { $Kh = 7.2 };
    >unless (/^[^#]/) { next }
    >$p = 3600 * $Kh / $F[0];
    >shift @F;
    >print int($p), "\t@F";


    #!/usr/bin/perl -w
    $Kh = 7.2;
    while (<DATA>)
    {
    next if /^#/;
    ($p, @F) = split(' ', chomp);
    $p = 3600 * $Kh / $p;
    print int($p), "\t@F";
    }
    __DATA__
    # Your data here...

    See man perldata and search for __DATA__.

    --
    Eric Amick
    Columbia, MD
    Eric Amick, Jul 26, 2003
    #2
    1. Advertising

  3. Eric Amick <> wrote:

    > ($p, @F) = split(' ', chomp);



    split() will always return a 1-element list, regardless of what is in $_.

    @F will always get the empty list, regardless of what is in $_.

    $p will get either a 1 or a 0 ( if you haven't messed with $/ ).

    Man oh man, that bug is going to present itself strangely.


    The return value from chomp() is not very useful.

    Seeing someone use it, therefore, is a red flag to me...


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jul 26, 2003
    #3
  4. Dan Jacobson

    Eric Amick Guest

    On Sat, 26 Jul 2003 12:18:00 -0500, (Tad McClellan)
    wrote:

    >Eric Amick <> wrote:
    >
    >> ($p, @F) = split(' ', chomp);

    >
    >
    >split() will always return a 1-element list, regardless of what is in $_.
    >
    >@F will always get the empty list, regardless of what is in $_.
    >
    >$p will get either a 1 or a 0 ( if you haven't messed with $/ ).
    >
    >Man oh man, that bug is going to present itself strangely.


    I was trying to be too clever. I wasn't thinking.

    Make that

    chomp;
    ($p, @F) = split;

    --
    Eric Amick
    Columbia, MD
    Eric Amick, Jul 27, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    14,538
    John C. Bollinger
    Jun 6, 2005
  2. Kobu
    Replies:
    10
    Views:
    606
    Keith Thompson
    Mar 4, 2005
  3. Alex
    Replies:
    11
    Views:
    1,306
    Keith Thompson
    Sep 12, 2006
  4. SpreadTooThin

    ifstream eof not reporting eof?

    SpreadTooThin, Jun 13, 2007, in forum: C++
    Replies:
    10
    Views:
    677
    James Kanze
    Jun 15, 2007
  5. Jan Burse
    Replies:
    67
    Views:
    1,029
    Jan Burse
    Mar 14, 2012
Loading...

Share This Page