Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Where to hitch the <<EOF to plaster input file?

Reply
Thread Tools

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

 
 
Dan Jacobson
Guest
Posts: n/a
 
      07-26-2003
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";
 
Reply With Quote
 
 
 
 
Eric Amick
Guest
Posts: n/a
 
      07-26-2003
On Sat, 26 Jul 2003 12:45:25 +0800, Dan Jacobson <(E-Mail Removed)>
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
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      07-26-2003
Eric Amick <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Eric Amick
Guest
Posts: n/a
 
      07-27-2003
On Sat, 26 Jul 2003 12:18:00 -0500, (E-Mail Removed) (Tad McClellan)
wrote:

>Eric Amick <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Now downloaded and installed without a hitch KevinD Windows 64bit 0 03-19-2008 05:22 AM
Strap or Hitch to Hold Camera for Quick Access HKEK Digital Photography 3 08-25-2006 07:22 PM
HEXUS.reviews :: Sima Hitch USB-101 transfer device Silverstrand Front Page News 0 08-15-2006 04:54 PM
Hitch in boot up Special Ed Computer Support 4 02-08-2006 04:18 AM
What's the XP hitch? Allan Computer Support 9 11-16-2003 09:48 PM



Advertisments