[28630] in Perl-Users-Digest
Perl-Users Digest, Issue: 9994 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 21 18:06:09 2006
Date: Tue, 21 Nov 2006 15:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 21 Nov 2006 Volume: 10 Number: 9994
Today's topics:
Re: Do I *have* to use 'OOP' to use modules? <nospam-abuse@ilyaz.org>
Re: Do I *have* to use 'OOP' to use modules? anno4000@radom.zrz.tu-berlin.de
Re: Do I *have* to use 'OOP' to use modules? <abigail@abigail.be>
Re: Do I *have* to use 'OOP' to use modules? <benmorrow@tiscali.co.uk>
Re: Do I *have* to use 'OOP' to use modules? anno4000@radom.zrz.tu-berlin.de
Re: DOS-Box script is running in set always on top <nimmerman@gmx.de>
File comparison <balaji.draj@gmail.com>
Re: File comparison anno4000@radom.zrz.tu-berlin.de
Re: mysql connection failing as CGI usenet@DavidFilmer.com
search and replace basics <balaji.draj@gmail.com>
Re: search and replace basics <mritty@gmail.com>
Re: search and replace basics <someone@example.com>
Re: Stuff a hash from two source files <john@castleamber.com>
Re: Stuff a hash from two source files <bradbrockman@yahoo.com>
Re: Stuff a hash from two source files <mritty@gmail.com>
Re: Stuff a hash from two source files <bradbrockman@yahoo.com>
Re: Stuff a hash from two source files <john@castleamber.com>
Re: Stuff a hash from two source files <DJStunks@gmail.com>
Re: Stuff a hash from two source files <bradbrockman@yahoo.com>
Re: Using a variable in a matching string <jgibson@mail.arc.nasa.gov>
Re: Using a variable in a matching string <someone@example.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 21 Nov 2006 19:12:02 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Do I *have* to use 'OOP' to use modules?
Message-Id: <ejvj22$1lnu$1@agate.berkeley.edu>
[A complimentary Cc of this posting was NOT [per weedlist] sent to
Ilya Zakharevich
<nospam-abuse@ilyaz.org>], who wrote in article <ejvdjb$1hqg$1@agate.berkeley.edu>:
> Thinking about it a little bit more, I see absolutely no reason to
> have attributes in the language proper. What is lost if all one has
> is a module `attr' with methods:
>
> $val = $o->__attr_get($a_name);
> $o->__attr_set($a_name, $val);
>
> $val = $o->__attr_get_($superclass_name, $a_name); # Allow "SUPER" as well
> $o->__attr_set_($superclass_name, $a_name, $val); # Likewise
>
> $class->__attr__def__($accessor_method, $mutator_method);
Of course, this should have been
$class->__attr__def__($a_name [, $accessor_method, $mutator_method] );
with default $accessor_method, $mutator_method keeping the attribute
in some appropriate out-of-band location ($class-dependent). So one
could even encode this into ->import, thus making
use attr qw(list of attribute names);
work...
Yours,
Ilya
------------------------------
Date: 21 Nov 2006 20:15:05 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Do I *have* to use 'OOP' to use modules?
Message-Id: <4sh529Fvt13sU1@mid.dfncis.de>
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote in comp.lang.perl.misc:
> [A complimentary Cc of this posting was NOT [per weedlist] sent to
> Ilya Zakharevich
> <nospam-abuse@ilyaz.org>], who wrote in article
> <ejvdjb$1hqg$1@agate.berkeley.edu>:
> > Thinking about it a little bit more, I see absolutely no reason to
> > have attributes in the language proper. What is lost if all one has
> > is a module `attr' with methods:
> >
> > $val = $o->__attr_get($a_name);
> > $o->__attr_set($a_name, $val);
> >
> > $val = $o->__attr_get_($superclass_name, $a_name); # Allow "SUPER" as well
> > $o->__attr_set_($superclass_name, $a_name, $val); # Likewise
> >
> > $class->__attr__def__($accessor_method, $mutator_method);
>
> Of course, this should have been
>
> $class->__attr__def__($a_name [, $accessor_method, $mutator_method] );
>
> with default $accessor_method, $mutator_method keeping the attribute
> in some appropriate out-of-band location ($class-dependent). So one
> could even encode this into ->import, thus making
>
> use attr qw(list of attribute names);
>
> work...
To answer your question from the parent posting, "Why not do it this
way" I'd first have to see how well the scheme works in practice.
That would mean implementation of at least one nontrivial (set of)
class(es) based on your suggestion. I can't answer that out of
hand.
Another question is: It's implemented as a pragma, so people are
free to build their classes that way or not. Does that matter?
This is the problem of many excellent CPAN modules in the Class::
and Object:: spaces: They work well and solve many problems -- in
a world where everybody uses them. How well they interoperate,
among themselves and with other, freely designed classes nobody
knows.
Here lies the objective advantage of inside-out classes: They
are freely inheritable (can be made base classes, without conflict)
by any other class, inside-out or not. This is an interesting
property for developers who want to publish their classes. Any
other class can use them by subclassing. That's what users of
dedicated OO languages miss in Perl.
Anno
------------------------------
Date: 21 Nov 2006 21:14:21 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Do I *have* to use 'OOP' to use modules?
Message-Id: <slrnem6r08.c8.abigail@alexandra.abigail.be>
Ilya Zakharevich (nospam-abuse@ilyaz.org) wrote on MMMMDCCCXXX September
MCMXCIII in <URL:news:ejvdjb$1hqg$1@agate.berkeley.edu>:
''
'' Thinking about it a little bit more, I see absolutely no reason to
'' have attributes in the language proper. What is lost if all one has
'' is a module `attr' with methods:
Usability.
If Larry had decided that Perl wouldn't have variables, but instead
functions 'set' and 'get', we could do the same in Perl as we can now.
But I'd be programming in a different language - I'm not interested
to program in minimalistic languages.
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: Tue, 21 Nov 2006 21:07:20 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Do I *have* to use 'OOP' to use modules?
Message-Id: <8d6c34-5vc.ln1@osiris.mauzo.dyndns.org>
Quoth anno4000@radom.zrz.tu-berlin.de:
>
> Here lies the objective advantage of inside-out classes: They
> are freely inheritable (can be made base classes, without conflict)
> by any other class, inside-out or not.
And, almost more importantly, can subclass any other class, inside-out
or not. That is, given a random class Foo whose implementation I am not
privy to, I can create an inside-out subclass Bar that definitely
doesn't tread on Foo's internals. Of course, I can only get at Foo's
attributes through Foo's public methods, but I should be doing that
anyway.
Ben
--
Raise your hand if you're invulnerable.
[benmorrow@tiscali.co.uk]
------------------------------
Date: 21 Nov 2006 22:29:27 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Do I *have* to use 'OOP' to use modules?
Message-Id: <4shcu7Fvs7o3U1@mid.dfncis.de>
Ben Morrow <benmorrow@tiscali.co.uk> wrote in comp.lang.perl.misc:
>
> Quoth anno4000@radom.zrz.tu-berlin.de:
> >
> > Here lies the objective advantage of inside-out classes: They
> > are freely inheritable (can be made base classes, without conflict)
> > by any other class, inside-out or not.
>
> And, almost more importantly, can subclass any other class, inside-out
> or not. That is, given a random class Foo whose implementation I am not
> privy to, I can create an inside-out subclass Bar that definitely
> doesn't tread on Foo's internals. Of course, I can only get at Foo's
> attributes through Foo's public methods, but I should be doing that
> anyway.
I believe you mean the technique where one uses the otherwise
unused object proper to hold an actual object of the parent
class?
I don't consider that an essential property of inside-out classes
but rather a (useful) quirk.
For one, it renders your class non-inside-out. It touches, err...
de-references its body (the parent class' accessors do) and is thus
in a state of sin. The result can no longer be used as a base class
by anything that isn't compatible with Foo in the usual sense.
Also, this technique can only be applied once, multiple inheritance
from non-inside-out classes requires other means.
That said, it *is* a useful property and I have been using it
at least once.
Anno
------------------------------
Date: 21 Nov 2006 14:33:07 -0800
From: "Daniel Kelber" <nimmerman@gmx.de>
Subject: Re: DOS-Box script is running in set always on top
Message-Id: <1164148387.270895.249050@h48g2000cwc.googlegroups.com>
Hi Len,
l v schrieb:
> Is this option available in a native windows DOS box?
Yes, this works: dropping a file from win explorer into a DOS box
writes the path and filename to STDIN (tested under WinXP).
> If you drag from windows explorer and hover over the dos box in the
> taskbar, the dos box will open on top. You then drop on the now opened
> dos box.
It would be better an faster if hovering over the taskbar is not
necessary.... :-)
Daniel
------------------------------
Date: 21 Nov 2006 13:01:17 -0800
From: "IJALAB" <balaji.draj@gmail.com>
Subject: File comparison
Message-Id: <1164142876.398032.299990@k70g2000cwa.googlegroups.com>
Hi All,
Thanks for all the guidance.
I have two files, which are of similar output but logged at different
times. They need to be compared for any changes in the data logged. But
the comparison should start only when the whole line matches. For ex:
I am pasting only few bytes from the log.It is actually 48 bytes wide.
File 1's output:
F0 00 10 00
F0 00 00 00
F0 00 7F 15 - from this point output matches with file2
F0 00 00 01
F0 00 0F FF
F0 00 7F 00
F0 00 FB 5D
F0 00 00 00
file2's output:
F0 00 7F 15
F0 00 00 01
F0 00 0F FF
F0 00 7F 00
F0 00 FB 5D
F0 00 00 00
So, I started like :
open(OUT, ">FileOutput.txt") || die "Can't open output
file.";
open(IN1, "<File1.txt") || die "Can't open input file 1.";
open(IN2, "<File2.txt") || die "Can't open input file
2.";
while (<IN1>) && (<IN2>)
{
foreach $line1(<IN1>)
{
foreach $line2(<IN2>)
{
if ($line1 = $line2)
{
print "Lines match";
}
else
{ print "Lines are not matching";}
}
}
}
but I dont know any better idea to compare the file outputs. Also, any
of these files might have some extra lines.
Any better idea that I can implement in Perl.
Bala
------------------------------
Date: 21 Nov 2006 22:10:28 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: File comparison
Message-Id: <4shbqkF102cn1U1@mid.dfncis.de>
IJALAB <balaji.draj@gmail.com> wrote in comp.lang.perl.misc:
> Hi All,
>
> Thanks for all the guidance.
>
> I have two files, which are of similar output but logged at different
> times. They need to be compared for any changes in the data logged. But
> the comparison should start only when the whole line matches. For ex:
>
> I am pasting only few bytes from the log.It is actually 48 bytes wide.
>
> File 1's output:
> F0 00 10 00
> F0 00 00 00
> F0 00 7F 15 - from this point output matches with file2
> F0 00 00 01
> F0 00 0F FF
> F0 00 7F 00
> F0 00 FB 5D
> F0 00 00 00
>
> file2's output:
>
> F0 00 7F 15
> F0 00 00 01
> F0 00 0F FF
> F0 00 7F 00
> F0 00 FB 5D
> F0 00 00 00
>
> So, I started like :
>
> open(OUT, ">FileOutput.txt") || die "Can't open output
> file.";
> open(IN1, "<File1.txt") || die "Can't open input file 1.";
> open(IN2, "<File2.txt") || die "Can't open input file
> 2.";
>
> while (<IN1>) && (<IN2>)
> {
> foreach $line1(<IN1>)
> {
> foreach $line2(<IN2>)
> {
> if ($line1 = $line2)
> {
> print "Lines match";
> }
> else
> { print "Lines are not matching";}
> }
> }
> }
>
> but I dont know any better idea to compare the file outputs. Also, any
> of these files might have some extra lines.
>
> Any better idea that I can implement in Perl.
That looks like something better done by diff, perhaps with some
Perl post-processing. Look into "diff -y" and related options,
if you're in a Unix or (I suppose) Cygwin environment. Otherwise
I don't know, but I'd still look for a specialized external program.
The algorithm you're looking for is far from trivial and not easy
to make fast.
Anno
------------------------------
Date: 21 Nov 2006 11:37:15 -0800
From: usenet@DavidFilmer.com
Subject: Re: mysql connection failing as CGI
Message-Id: <1164137835.284472.275760@h48g2000cwc.googlegroups.com>
ianatkinsonbsc@gmail.com wrote:
> but the output is no different, i.e. it still works as expected from
> the command line but outputs the same HTML code when viewed in a
> browser:
Add this near the top of your code:
use CGI::Carp qw{ fatalsToBrowser warningsToBrowser };
That will let you see STDERR in your browser... there might be
something informative there.
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 21 Nov 2006 11:45:32 -0800
From: "IJALAB" <balaji.draj@gmail.com>
Subject: search and replace basics
Message-Id: <1164138331.768575.305880@h48g2000cwc.googlegroups.com>
Hi,
My file is like
(20:34:08.747) Rx 48 bytes
<F0><00><10><00><05><18><00><73><1B><0D><00>
(20:34:08.810) Rx 48 bytes
<00><00><00><0B><FF><7F><15><00><00><00><00><00><00><18><FF><7F><15><00>
>From a file(Text1.txt), I have to remove the text before 48 bytes and
retain the remaining string.I am trying to do the following
open(FILE1, ">Text1.txt") || die "Can't open output file.";
while(<FILE1>)
{
s/*.*bytes //g;
print FILE1 ;
}
I am unable to achieve what I want. In the manual, it is given as $'
will print everything after the match string. but that also doesn't
work.
Also, I need to remove the angle brackets. I did the same thing
s/[<>]//g;
in vain.
can some one help me out?
-bala
------------------------------
Date: 21 Nov 2006 11:55:38 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: search and replace basics
Message-Id: <1164138938.564008.115480@m7g2000cwm.googlegroups.com>
IJALAB wrote:
> My file is like
>
> (20:34:08.747) Rx 48 bytes
> <F0><00><10><00><05><18><00><73><1B><0D><00>
> (20:34:08.810) Rx 48 bytes
> <00><00><00><0B><FF><7F><15><00><00><00><00><00><00><18><FF><7F><15><00>
>
>
> >From a file(Text1.txt), I have to remove the text before 48 bytes and
> retain the remaining string.I am trying to do the following
> open(FILE1, ">Text1.txt") || die "Can't open output file.";
This attempts to open the file for WRITING, not reading. It will
clobber your input file.
>
> while(<FILE1>)
> {
> s/*.*bytes //g;
This is a compilation error, as you can't have a * following nothing.
It makes no sense.
> print FILE1 ;
Now you're trying to print to the filehandle you jsut read from. That
does't make any sense. Open a file for reading, read from the file,
make changes, and print the changed lines to a new file.
>
> }
>
> I am unable to achieve what I want. In the manual, it is given as $'
> will print everything after the match string.
Yes, and? Why do you think you want that? Your regexp is
theoretically intended to change the string to eliminate the parts you
don't need, leaving you with just the parts you do need.
> but that also doesn't work.
"doesn't work" is the worst possible error description.
> Also, I need to remove the angle brackets. I did the same thing
>
> s/[<>]//g;
>
> in vain.
"in vain" is the same as "doesn't work". What is that supposed to
mean? How did it go wrong?
> can some one help me out?
You would do well to read a decent Perl tutorial....
#!/usr/bin/perl
use strict;
use warnings;
open my $fh, '<', 'Text1.txt' or die "Cannot open Text1.txt: $!";
open my $ofh, '>', 'Text1.mod.txt' or die "Cannot open Text1.mod.txt:
$!";
while (my $line = <$fh>) {
$line =~ s/^.*?bytes//;
$line =~ tr/<>//d;
print $ofh $line;
}
close $fh;
close $ofh;
__END__
------------------------------
Date: Tue, 21 Nov 2006 20:36:28 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: search and replace basics
Message-Id: <grJ8h.8978$rB6.8432@clgrps13>
IJALAB wrote:
>
> My file is like
>
> (20:34:08.747) Rx 48 bytes
> <F0><00><10><00><05><18><00><73><1B><0D><00>
> (20:34:08.810) Rx 48 bytes
> <00><00><00><0B><FF><7F><15><00><00><00><00><00><00><18><FF><7F><15><00>
>
>
>>From a file(Text1.txt), I have to remove the text before 48 bytes and
> retain the remaining string.I am trying to do the following
> open(FILE1, ">Text1.txt") || die "Can't open output file.";
>
> while(<FILE1>)
> {
> s/*.*bytes //g;
> print FILE1 ;
>
> }
>
> I am unable to achieve what I want. In the manual, it is given as $'
> will print everything after the match string. but that also doesn't
> work.
>
> Also, I need to remove the angle brackets. I did the same thing
>
> s/[<>]//g;
>
> in vain.
( $^I, @ARGV ) = ( '.bak', 'Text1.txt' );
while ( <> ) {
s/.*?bytes *//;
tr/<>//d;
print;
}
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: 21 Nov 2006 19:26:55 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Stuff a hash from two source files
Message-Id: <Xns988288CE52B93castleamber@130.133.1.4>
John Bokma <john@castleamber.com> wrote:
> Maye
Aye, those damn pirates now stole the key next to the v :-(
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: 21 Nov 2006 11:47:11 -0800
From: "banker123" <bradbrockman@yahoo.com>
Subject: Re: Stuff a hash from two source files
Message-Id: <1164138430.934878.18790@k70g2000cwa.googlegroups.com>
My actual code.
#!/usr/bin/perl
#use strict;
#use warnings;
open ('info', 'C:/sort.txt') or die "Cannot open file: $!";
open ('box', 'C:/box.txt') or die "Cannot open file: $!";
my %data;
while ( <info> ) {
($box,$prior)=split;
}
while ( <box> ) {
($lockbox,$group)=split;
}
$data {$box} = { group => $group , prior => $prior} ;
for my $table ( sort by_type keys %data ) {
my @data = ($table, @{ $data{$table} } {qw/group prior/});
print "@data\n";
}
sub by_type {
$data{$a}{prior} <=> $data{$b}{prior};
}
------------------------------
Date: 21 Nov 2006 11:49:37 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Stuff a hash from two source files
Message-Id: <1164138577.021577.28220@k70g2000cwa.googlegroups.com>
banker123 wrote:
> My actual code.
>
> #!/usr/bin/perl
> #use strict;
> #use warnings;
This is plugging your fingers in your ears and shouting "LA LA LA I
CAN'T HEAR YOU!!!!". If you don't want Perl to tell you what you're
doing wrong, why are you bothering to ask us what you did wrong?
>
> open ('info', 'C:/sort.txt') or die "Cannot open file: $!";
> open ('box', 'C:/box.txt') or die "Cannot open file: $!";
>
> my %data;
> while ( <info> ) {
> ($box,$prior)=split;
> }
> while ( <box> ) {
> ($lockbox,$group)=split;
> }
> $data {$box} = { group => $group , prior => $prior} ;
So you didn't bother to listen to the suggestions that either John or I
gave you? Why bother asking us?
Good bye.
Paul Lalli
------------------------------
Date: 21 Nov 2006 11:59:06 -0800
From: "banker123" <bradbrockman@yahoo.com>
Subject: Re: Stuff a hash from two source files
Message-Id: <1164139146.517165.85030@j44g2000cwa.googlegroups.com>
> This is plugging your fingers in your ears and shouting "LA LA LA I
> CAN'T HEAR YOU!!!!". If you don't want Perl to tell you what you're
> doing wrong, why are you bothering to ask us what you did wrong?
Same result, few changes made after turning on strict and warnings as
suggested, and declaring the hash.
#!/usr/bin/perl
use strict;
use warnings;
open ('info', 'C:/sort.txt') or die "Cannot open file: $!";
open ('box', 'C:/box.txt') or die "Cannot open file: $!";
my %data;
while ( <info> ) {
my ($box,$prior)=split;
while ( <box> ) {
my ($lockbox,$group)=split;
$data {$box} = { group => $group , prior => $prior} ;
}
}
for my $table ( sort by_type keys %data ) {
my @data = ($table, @{ $data{$table} } {qw/group prior/});
print "@data\n";
}
sub by_type {
$data{$a}{prior} <=> $data{$b}{prior};
}
------------------------------
Date: 21 Nov 2006 20:43:49 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Stuff a hash from two source files
Message-Id: <Xns988295D7E35EEcastleamber@130.133.1.4>
"banker123" <bradbrockman@yahoo.com> wrote:
>> This is plugging your fingers in your ears and shouting "LA LA LA I
>> CAN'T HEAR YOU!!!!". If you don't want Perl to tell you what you're
>> doing wrong, why are you bothering to ask us what you did wrong?
>
> Same result, few changes made after turning on strict and warnings as
> suggested, and declaring the hash.
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> open ('info', 'C:/sort.txt') or die "Cannot open file: $!";
> open ('box', 'C:/box.txt') or die "Cannot open file: $!";
>
> my %data;
> while ( <info> ) {
> my ($box,$prior)=split;
>
> while ( <box> ) {
> my ($lockbox,$group)=split;
> $data {$box} = { group => $group , prior => $prior} ;
> }
> }
>
> for my $table ( sort by_type keys %data ) {
> my @data = ($table, @{ $data{$table} } {qw/group prior/});
> print "@data\n";
> }
>
> sub by_type {
> $data{$a}{prior} <=> $data{$b}{prior};
> }
Cannot open file: No such file or directory at C:\Documents and Settings
\John\My Documents\foo.pl line 5.
perldoc -f open
Also, if you report an error, it might be useful to provide some
additional info, e.g.
my $filename = ....
.... or die "Can't open '$filename' for reading: $!";
^ errmesg
^ ^
what file action that failed
You got one out of 3.
(And if your files are really directly on drive C: ... aargh)
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: 21 Nov 2006 12:45:18 -0800
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Stuff a hash from two source files
Message-Id: <1164141918.780498.197400@e3g2000cwe.googlegroups.com>
banker123 wrote:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> open ('info', 'C:/sort.txt') or die "Cannot open file: $!";
> open ('box', 'C:/box.txt') or die "Cannot open file: $!";
>
> my %data;
> while ( <info> ) {
> my ($box,$prior)=split;
>
> while ( <box> ) {
> my ($lockbox,$group)=split;
> $data {$box} = { group => $group , prior => $prior} ;
> }
> }
>
> for my $table ( sort by_type keys %data ) {
> my @data = ($table, @{ $data{$table} } {qw/group prior/});
> print "@data\n";
> }
>
> sub by_type {
> $data{$a}{prior} <=> $data{$b}{prior};
> }
okay, now we're getting somewhere. code that compiles.
what you're doing above is going through every line of <box> for each
line of <info>. what I think you want to be doing is building the
'prior' key value pair as you go through the info file, then adding the
'group' key value pair to the hash for each box as you go through each
line of <box>.
something like this: (untested)
my %data;
while (<info>) {
($box, $prior) = split;
$data{$box}{prior} = $prior;
}
while (<box>) {
($box,$group) = split;
$data{$box}{group} = $group;
}
-jp
------------------------------
Date: 21 Nov 2006 13:40:10 -0800
From: "banker123" <bradbrockman@yahoo.com>
Subject: Re: Stuff a hash from two source files
Message-Id: <1164145209.993566.74450@e3g2000cwe.googlegroups.com>
DJ Stunks wrote:
> what you're doing above is going through every line of <box> for each
> line of <info>. what I think you want to be doing is building the
> 'prior' key value pair as you go through the info file, then adding the
> 'group' key value pair to the hash for each box as you go through each
> line of <box>.
Exactly!
> something like this: (untested)
>
> my %data;
> while (<info>) {
> ($box, $prior) = split;
> $data{$box}{prior} = $prior;
> }
>
> while (<box>) {
> ($box,$group) = split;
> $data{$box}{group} = $group;
Worked great, thanks!
------------------------------
Date: Tue, 21 Nov 2006 11:23:28 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Using a variable in a matching string
Message-Id: <211120061123282390%jgibson@mail.arc.nasa.gov>
In article <1164133103.273630.17350@j44g2000cwa.googlegroups.com>,
deadpickle <deadpickle@gmail.com> wrote:
> I want the data to be saved to a text file in this format:
> KGRI
> KLNK
> KHSI
>
> And then reads into the program and then run through the match string.
> I cant seem to get it to work correctly. Any help?
>
>
> use strict;
> use warnings;
> $\ = "\n";
> open ID, '<', 'stations.txt' or die "cannot open 'stations.txt' $!";
> open TBL, 'stidtbl.txt' or die "cannot open 'stidtbl.txt' $!";
You should check the opens for errors.
> while ( my @tbl = <TBL> ) { #reads in a table of station IDs
This reads the entire file into the array @tbl in the first pass
through the while loop (hopefully, there will only be one pass). You
should read one line at-a-time into a scalar or eliminate the while
loop.
> my $idtbl = join ("|", @tbl);
> chop ($idtbl);
You should chomp (not chop) all of the elements of @tbl before joining
into a scalar. If you are trying to get the whole file into a scalar.
see 'perldoc -q entire' "How can I read in an entire file all at once".
chomp(@tbl);
> print $idtbl;
[second loop snipped]
>
>
> $idtbl keeps outputing:
> KGRI
> |KHSI
> |KLNK
> and I think it would work if it read in: KGRI|KHSI|KLNK
>
It is outputting that because you have embedded newlines in $idtbl
because you did not chomp the input records.
------------------------------
Date: Tue, 21 Nov 2006 21:06:50 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Using a variable in a matching string
Message-Id: <KTJ8h.8979$rB6.2309@clgrps13>
deadpickle wrote:
> I want the data to be saved to a text file in this format:
> KGRI
> KLNK
> KHSI
>
> And then reads into the program and then run through the match string.
> I cant seem to get it to work correctly. Any help?
>
>
> use strict;
> use warnings;
> $\ = "\n";
> open ID, '<', 'stations.txt' or die "cannot open 'stations.txt' $!";
> open TBL, 'stidtbl.txt' or die "cannot open 'stidtbl.txt' $!";
> while ( my @tbl = <TBL> ) { #reads in a table of station IDs
> my $idtbl = join ("|", @tbl);
> chop ($idtbl);
> print $idtbl;
> while ( my $stations = <ID> ) { #finds the lat and long of a searched
> station
> next unless $stations =~ /\A.{20}($idtbl)\s+(.+)/;
> my @id = split (" ",$2);
> if (length($id[1]) == 5) {
> chop ($id[3]);
> chop ($id[5]);
> my $p = ".";
> my $lat = $id[2] . $p . $id[3];
> my $long = $id[4] . $p . $id[5];
> my @stid = ( $id[0], $lat, $long);
> print "@stid";
> }
> else {
> chop ($id[2]);
> chop ($id[4]);
> my $p = ".";
> my $lat = $id[1] . $p . $id[2];
> my $long = $id[3] . $p . $id[4];
> my @stid = ( $id[0], $lat, $long);
> print "@stid";
> }
> }
> }
>
>
> $idtbl keeps outputing:
> KGRI
> |KHSI
> |KLNK
> and I think it would work if it read in: KGRI|KHSI|KLNK
use strict;
use warnings;
open TBL, '<', 'stidtbl.txt' or die "cannot open 'stidtbl.txt' $!";
# reads in a table of station IDs
my $idtbl = join '|', map { chomp; $_ } <TBL>;
close TBL;
open ID, '<', 'stations.txt' or die "cannot open 'stations.txt' $!";
# finds the lat and long of a searched station
while ( my $stations = <ID> ) {
next unless $stations =~ /\A.{20}($idtbl)\s+(.+)/o;
my @id = split ' ' ,$2;
splice @id, 1, 1 if length( $id[ 1 ] ) == 5;
s/\D+//g for @id;
print "$id[0] $id[1].$id[2] $id[3].$id[4]\n";
}
close ID;
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 9994
***************************************