[28629] in Perl-Users-Digest
Perl-Users Digest, Issue: 9993 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 21 14:06:07 2006
Date: Tue, 21 Nov 2006 11:05:12 -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: 9993
Today's topics:
Re: Do I *have* to use 'OOP' to use modules? <nospam-abuse@ilyaz.org>
DOS-Box script is running in set always on top <nimmerman@gmx.de>
Re: DOS-Box script is running in set always on top <john@castleamber.com>
Re: DOS-Box script is running in set always on top <nimmerman@gmx.de>
Re: DOS-Box script is running in set always on top <veatchla@yahoo.com>
generic increment of number/string <alexxx.magni@gmail.com>
Re: generic increment of number/string <mritty@gmail.com>
Re: generic increment of number/string <veatchla@yahoo.com>
Re: Matching and Regular Expressions <jgibson@mail.arc.nasa.gov>
Re: Multiline substitution <uri@stemsystems.com>
mysql connection failing as CGI ianatkinsonbsc@gmail.com
Re: mysql connection failing as CGI <spamtrap@dot-app.org>
Re: mysql connection failing as CGI ianatkinsonbsc@gmail.com
parsing from secure apache site. simple authentication <aomanchuria@gmail.com>
Re: parsing from secure apache site. simple authenticat <spamtrap@dot-app.org>
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 <john@castleamber.com>
Submit buttons and param name <pws5252@gmail.com>
Using a variable in a matching string <deadpickle@gmail.com>
Re: using an array to set up hash keys <uri@stemsystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 21 Nov 2006 17:38:51 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Do I *have* to use 'OOP' to use modules?
Message-Id: <ejvdjb$1hqg$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
<anno4000@radom.zrz.tu-berlin.de>], who wrote in article <4sdl2lFuoj51U1@mid.dfncis.de>:
> > AFAIU, having attributes in the language would bring absolutely no
> > benefits to the "merely users". The "developers", of course, are in a
> > very different situation...
>
> You are right, it doesn't make a difference to the end user.
>
> The contrasting situation would be development of a cluster of two or
> more classes by a single developer (or team). Essentially this is the
> only situation where inheritance among traditional Perl classes can
> be handled because the derived class must account for implementation
> details of the base class.
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);
??? Then if a module wants to use attributes, just put 'attr' into @ISA...
(Of course, this assumes that attributes are inherited through @ISA -
which is trivial to implement.)
Puzzled,
Ilya
------------------------------
Date: 21 Nov 2006 08:54:35 -0800
From: "Daniel Kelber" <nimmerman@gmx.de>
Subject: DOS-Box script is running in set always on top
Message-Id: <1164128075.527627.5470@j44g2000cwa.googlegroups.com>
I want a perl script to set the DOS-Box it is running in to be "always
on top".
Maybe I can use SetWindowPos from user32.dll but therefor I need the
window handle of the DOS-Box. How can I get out this handle?
Is there any easy way to get the window on top?
------------------------------
Date: 21 Nov 2006 17:03:37 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: DOS-Box script is running in set always on top
Message-Id: <Xns98827082DA5E2castleamber@130.133.1.4>
"Daniel Kelber" <nimmerman@gmx.de> wrote:
> I want a perl script to set the DOS-Box it is running in to be "always
> on top".
> Maybe I can use SetWindowPos from user32.dll but therefor I need the
> window handle of the DOS-Box. How can I get out this handle?
> Is there any easy way to get the window on top?
If you want to keep an eye on things, why not open your own window on top
with Tk (I am quite sure this is possible)?
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: 21 Nov 2006 09:17:40 -0800
From: "Daniel Kelber" <nimmerman@gmx.de>
Subject: Re: DOS-Box script is running in set always on top
Message-Id: <1164129460.595443.228200@m7g2000cwm.googlegroups.com>
John Bokma schrieb:
> If you want to keep an eye on things, why not open your own window on top
> with Tk (I am quite sure this is possible)?
>
> --
> John
Hi John,
the aim is to drag a file from the windows explorer and drop it in the
DOS-Box where the script is waiting with
<STDIN>;
When I drag the file from windows explorer the DOS box gets in
background so dropping is more complicated...
------------------------------
Date: Tue, 21 Nov 2006 12:41:35 -0600
From: l v <veatchla@yahoo.com>
Subject: Re: DOS-Box script is running in set always on top
Message-Id: <12m6i2tai4baa1e@news.supernews.com>
Daniel Kelber wrote:
> John Bokma schrieb:
>
>> If you want to keep an eye on things, why not open your own window on top
>> with Tk (I am quite sure this is possible)?
>>
>> --
>> John
>
> Hi John,
> the aim is to drag a file from the windows explorer and drop it in the
> DOS-Box where the script is waiting with
>
> <STDIN>;
>
> When I drag the file from windows explorer the DOS box gets in
> background so dropping is more complicated...
>
Is this option available in a native windows DOS box?
Perhaps something like "Actual Title Buttons" from Actual Tools in more
appropriate. This is not a sales pitch nor do I own their products.
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.
--
Len
------------------------------
Date: 21 Nov 2006 08:21:16 -0800
From: "alexxx.magni@gmail.com" <alexxx.magni@gmail.com>
Subject: generic increment of number/string
Message-Id: <1164126076.529119.191690@f16g2000cwb.googlegroups.com>
hi everybody,
there is some way to easily loop a padded variable, getting:
0001
0002
0003
0004
...
?
I'd like to do it in a simple for() loop, and I wanted to avoid
checking the total string length...
thanks!
Alessandro Magni
------------------------------
Date: 21 Nov 2006 09:28:01 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: generic increment of number/string
Message-Id: <1164130081.631189.144560@j44g2000cwa.googlegroups.com>
alexxx.magni@gmail.com wrote:
> hi everybody,
> there is some way to easily loop a padded variable, getting:
> 0001
> 0002
> 0003
> 0004
> ...
>
> ?
>
> I'd like to do it in a simple for() loop, and I wanted to avoid
> checking the total string length...
You've made it more difficult than it is, probably by thinking too much
like a C programmer. :-)
for my $num ('0001' .. '0100') {
print "$num\n";
}
Paul Lalli
------------------------------
Date: Tue, 21 Nov 2006 12:44:38 -0600
From: l v <veatchla@yahoo.com>
Subject: Re: generic increment of number/string
Message-Id: <12m6i8jbpmqpaa4@news.supernews.com>
alexxx.magni@gmail.com wrote:
> hi everybody,
> there is some way to easily loop a padded variable, getting:
> 0001
> 0002
> 0003
> 0004
> ...
>
> ?
>
> I'd like to do it in a simple for() loop, and I wanted to avoid
> checking the total string length...
>
> thanks!
>
>
> Alessandro Magni
>
How about ....
for my $number (1 .. 100) {
printf "%04d\n", $number;
}
--
Len
------------------------------
Date: Tue, 21 Nov 2006 09:48:25 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Matching and Regular Expressions
Message-Id: <211120060948251125%jgibson@mail.arc.nasa.gov>
In article <1164048050.153086.212100@h54g2000cwb.googlegroups.com>,
deadpickle <deadpickle@gmail.com> wrote:
> Here is a quick code I came up with:
[non-working program snipped]
Here is a sample using unpack (I truncated data lines):
#!/usr/local/bin/perl
use strict;
use warnings;
my($location,$date) = unpack "A20 A", <DATA>;
<DATA>; # skip header row
my %stid;
while(my $line = <DATA>) {
my($cd,$station,$icao,$iata,$synop,$lat,$long,$elev) =
unpack 'A2 x A17 A4 x2 A3 x3 A5 x2 A6 x2 A7 A5', $line;
$stid{$icao} = $iata;
}
if( exists $stid{KBIS} ) {
print "IATA for KBIS is $stid{KBIS}\n";
}
__DATA__
NORTH DAKOTA 24-JUN-05
CD STATION ICAO IATA SYNOP LAT LONG ELEV
ND BISMARCK KBIS BIS 72764 46 46N 100 45W 505
ND DEVILS LAKE KDVL DVL 72757 48 07N 098 55W 443
ND DEVILS LAKE KP11 P11 72758 48 07N 098 55W 443
ND DICKINSON KDIK DIK 46 48N 102 48W 788
ND FARGO KFAR FAR 72753 46 56N 096 49W 277
------------------------------
Date: Tue, 21 Nov 2006 12:49:47 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Multiline substitution
Message-Id: <x7odr0d70k.fsf@mail.sysarch.com>
>>>>> "g" == gooliver <gooliverNOSP@mlibero.it> writes:
g> In data Tue, 21 Nov 2006 14:10:29 +0100, Paul Lalli <mritty@gmail.com>
g> ha scritto:
>> "Doctor, Doctor, it hurts when I raise my arm like this!!"
g> The doctor replies, "Then don't raise your arm over your head." (-:
g> ...
g> $code="";
not needed with .=.
and you didn't use strict or warnings.
g> while ( $r = <IN> ) {
g> $code = $code . $r;
g> }
gack! use File::Slurp. yours is the slowest way to read in whole files.
g> close(IN);
g> $code =~ s{ \$\$ (.*?) \$\$ }{\\[$1\\]}gxms;
g> print OUT $code;
File::Slurp can also handle outputting files.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 21 Nov 2006 10:03:17 -0800
From: ianatkinsonbsc@gmail.com
Subject: mysql connection failing as CGI
Message-Id: <1164132197.153553.291800@j44g2000cwa.googlegroups.com>
Hi,
I have a strange problem and I'm hoping someone can help. I've bought
some new hosting which comes with a MySQL database but I'm struggling
to get it working with any perl scripts; the hosting support are being
no help so I've had to come here, sorry guys!
The problem basically is that when the script is run as a CGI script it
won't connect to the database, however if I run the same script from
the command line (I have SSH access to the server) it runs fine.
The script is as follows (very simple):
--------------------------------------------------
#! /usr/bin/perl
use DBI;
print "Content-type: text/html\n\n";
print "<html><head></head><body>\n\nres:\n\n";
$dbh = DBI->connect('DBI:mysql:dbname:213.171.218.249:3306', 'dbuser',
'dbpass') || die "Content-type:text/html\n\ncon err!";
my $SQL = "SELECT * FROM numbers";
$sth = $dbh->prepare($SQL);
$sth->execute() || print "SQL Error on $SQL !!";
while (@row = $sth->fetchrow_array) { print @row; print "\n"; }
print "</body></html>";
--------------------------------------------------
And if I run it from the command line:
[domain1201232@ssh5 cgi-bin]$ perl numbers.pl
Content-type: text/html
<html><head></head><body>
res:
1
10
15
</body></html>
As you can see it connects to the database and retrieves the 3 ints sat
in there. If I run this from the CGI-bin however the only code output
is:
<html><head></head><body>
res:
i.e. the script falls over when it tries to make the database
connection and goes no further.
The hosting support are saying that I have not formed the connection
string properly, however if that was the case it wouldn't work from the
command line surely? I have also copied the script over to my machine
at home (verbatim and connecting to the same MySQL server) and it runs
fine from there also.
It seems to me like they have a firewalling problem maybe but I don't
have access to the Apache logs so I'm at a loss as to what else I can
try really. I did try the same thing in PHP (just using PHP syntax) and
that works OK, both on the command line and over the web which was
bringing me back round to the idea that it's a Perl problem, but I
really can't see anything wrong with it and if the syntax was wrong
it'd surely crap out on the command line as well!
Any ideas?
Thanks,
Ian.
------------------------------
Date: Tue, 21 Nov 2006 13:23:24 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: mysql connection failing as CGI
Message-Id: <m2y7q43bhf.fsf@Sherm-Pendleys-Computer.local>
ianatkinsonbsc@gmail.com writes:
> I have a strange problem and I'm hoping someone can help. I've bought
> some new hosting which comes with a MySQL database but I'm struggling
> to get it working with any perl scripts; the hosting support are being
> no help so I've had to come here, sorry guys!
>
> The problem basically is that when the script is run as a CGI script it
> won't connect to the database, however if I run the same script from
> the command line (I have SSH access to the server) it runs fine.
>
> The script is as follows (very simple):
>
> --------------------------------------------------
>
> #! /usr/bin/perl
use strict;
use warnings;
> use DBI;
>
> print "Content-type: text/html\n\n";
> print "<html><head></head><body>\n\nres:\n\n";
>
> $dbh = DBI->connect('DBI:mysql:dbname:213.171.218.249:3306', 'dbuser',
> 'dbpass') || die "Content-type:text/html\n\ncon err!";
Well, the first thing to do is ask Perl what went wrong:
my $dbh = DBI->connect('...');
if ( $dbh->err ) {
print 'DBI Error: ', $dbh->errstr, '<br>';
exit;
}
> As you can see it connects to the database and retrieves the 3 ints sat
> in there. If I run this from the CGI-bin however the only code output
> is:
When a database connection succeeds for one user but fails for another, the
most common cause is that the server account has a different level of access
to the database. For instance, the web server process may be running inside
of a chroot "jail" in which /tmp/mysql.sock isn't visible.
There are any number of guesses I could give you though - Asking the database
handle for its error string will tell you for certain what went wrong.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 21 Nov 2006 10:52:40 -0800
From: ianatkinsonbsc@gmail.com
Subject: Re: mysql connection failing as CGI
Message-Id: <1164135160.415466.135490@k70g2000cwa.googlegroups.com>
Sherm Pendley wrote:
> Well, the first thing to do is ask Perl what went wrong:
>
> my $dbh = DBI->connect('...');
> if ( $dbh->err ) {
> print 'DBI Error: ', $dbh->errstr, '<br>';
> exit;
> }
I have turned on strict/warnings and asked the script to output the
errors as follows:
-------------------------------
#! /usr/bin/perl
use DBI;
use strict;
use warnings;
print "Content-type: text/html\n\n";
print "<html><head></head><body>\n\nres:\n\n";
$DBI::dbh =
DBI->connect("DBI:mysql:database=dbname;host=213.171.218.249",
"dbuser", "dbpass") || print "err $DBI::errstr $DBI::err";
my $SQL = "SELECT * FROM numbers";
my $sth = $DBI::dbh->prepare($SQL);
$sth->execute();
while (my @row = $sth->fetchrow_array) { print @row; print "\n"; }
print "</body></html>";
-------------------------------
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:
<html><head></head><body>
res:
So it's as if the script doesn't get chance to realise that the
connection has failed, either getting stuck or crashing out without
printing the error? I agree the error would be very useful!
Ian.
------------------------------
Date: 21 Nov 2006 09:57:49 -0800
From: "aomanchuria" <aomanchuria@gmail.com>
Subject: parsing from secure apache site. simple authentication
Message-Id: <1164131869.078772.139780@b28g2000cwb.googlegroups.com>
Gurus,
I need to create a perl script that runs on a local machine. The script
goes to an Apache http site (not https) that has simple authentication.
Normally you go to the index.htm on the browser, and you get a
username/password challenge window. So the question is, how do I send
my username/password from a text file or some variable in the local
perl scrip. This is the only one thing keeping me from making my script
work.
Manchuria
------------------------------
Date: Tue, 21 Nov 2006 13:09:56 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: parsing from secure apache site. simple authentication
Message-Id: <m23b8c4qob.fsf@Sherm-Pendleys-Computer.local>
"aomanchuria" <aomanchuria@gmail.com> writes:
> I need to create a perl script that runs on a local machine. The script
> goes to an Apache http site (not https) that has simple authentication.
I assume that by "goes to" you're referring to a retrieving a page with the
LWP module, and by "simple" authentication you mean HTTP's basic auth.
If you meant something else - you should have said so. :-\
> Normally you go to the index.htm on the browser, and you get a
> username/password challenge window. So the question is, how do I send
> my username/password from a text file or some variable in the local
> perl scrip. This is the only one thing keeping me from making my script
> work.
From "perldoc lwpcook". (Domain changed to .invalid protect the innocent.)
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$req = HTTP::Request->new(GET => 'http://www.linpro.invalid/secret/');
$req->authorization_basic('aas', 'mypassword');
print $ua->request($req)->as_string;
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 21 Nov 2006 10:02:00 -0800
From: "banker123" <bradbrockman@yahoo.com>
Subject: Stuff a hash from two source files
Message-Id: <1164132120.451779.170540@m73g2000cwd.googlegroups.com>
I am trying to populate a hash from two source files. The code below
only populates the last elements from the source files. I woul like to
populate the hash with all the elements foiund in the source files.
!/usr/bin/perl
use strict;
use warnings;
while ( <data1> ) {
($box,$priority)=split;
}
while ( <data2> ) {
($lockbox,$group)=split;
}
my %data = ( $box => { group => "$group" , priority => "$priority"} );
data1
712480 3
712481 2
712482 1
data2
712480 firstgreen
712481 firstblack
712482 firstblue
------------------------------
Date: 21 Nov 2006 10:09:35 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Stuff a hash from two source files
Message-Id: <1164132575.262330.310360@j44g2000cwa.googlegroups.com>
banker123 wrote:
> I am trying to populate a hash from two source files. The code below
> only populates the last elements from the source files.
That's all you told it to do.
> I woul like to
> populate the hash with all the elements foiund in the source files.
>
> !/usr/bin/perl
> use strict;
Please don't lie to us just to avoid us yelling about not using strict
and warnings. Your code does not compile with strict enabled. Post
your real code.
> use warnings;
>
> while ( <data1> ) {
There is no such filehandle.
> ($box,$priority)=split;
No such variables were ever declared.
> }
> while ( <data2> ) {
There is no such filehandle.
> ($lockbox,$group)=split;
No such variables were ever declared.
> }
>
> my %data = ( $box => { group => "$group" , priority => "$priority"} );
perldoc -q quoting
In addition to all the compilation problems, your central problem is
that your algorithm makes no sense. You read in all lines from one
file, overwriting the contents of two variables each time through.
Then you read in all lines from another file, overwriting the contents
of two other variables each time through. Then you finally declare a
hash, and populate it with exactly one key/value pair, that uses three
of those variables - which of course have only the last values read in
for each.
Step one: *actually* enable strict and warnings.
Step two: declare your hash before opening any files.
Step three: figure out what you actually want to make this hash look
like. You've given no information of any kind that would tell us how
the lines in one file relate to the lines in the other file, so there's
no way of knowing how you want the structure to end up.
Paul Lalli
------------------------------
Date: 21 Nov 2006 18:20:06 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Stuff a hash from two source files
Message-Id: <Xns98827D7A8AD9Ecastleamber@130.133.1.4>
"banker123" <bradbrockman@yahoo.com> wrote:
> I am trying to populate a hash from two source files. The code below
> only populates the last elements from the source files. I woul like
to
> populate the hash with all the elements foiund in the source files.
>
> !/usr/bin/perl
> use strict;
> use warnings;
>
> while ( <data1> ) {
> ($box,$priority)=split;
> }
> while ( <data2> ) {
> ($lockbox,$group)=split;
> }
>
> my %data = ( $box => { group => "$group" , priority => "$priority"} );
Post real code, not something you typed in, untested:
"use" not allowed in expression at C:\Documents and Settings\John\My
Documents\use.pl line 2, at end of line
syntax error at C:\Documents and Settings\John\My Documents\use.pl line
2, near "perl
use strict"
BEGIN not safe after errors--compilation aborted at C:\Documents and
Settings\John\My Documents\use.pl line 3.
Even if I consider the first line a copy mistake, and add the # I get:
Global symbol "$box" requires explicit package name at C:\Documents and
Settings\John\My Documents\use.pl line 6.
Global symbol "$priority" requires explicit package name at C:\Documents
and Settings\John\My Documents\use.pl line 6.
Bareword "data1" not allowed while "strict subs" in use at C:\Documents
and Settings\John\My Documents\use.pl line 8.
Global symbol "$lockbox" requires explicit package name at C:\Documents
and Settings\John\My Documents\use.pl line 9.
Global symbol "$group" requires explicit package name at C:\Documents
and Settings\John\My Documents\use.pl line 9.
Bareword "data2" not allowed while "strict subs" in use at C:\Documents
and Settings\John\My Documents\use.pl line 12.
Global symbol "$box" requires explicit package name at C:\Documents and
Settings\John\My Documents\use.pl line 12.
Global symbol "$group" requires explicit package name at C:\Documents
and Settings\John\My Documents\use.pl line 12.
Global symbol "$priority" requires explicit package name at C:\Documents
and Settings\John\My Documents\use.pl line 12.
Bareword "group" not allowed while "strict subs" in use at C:\Documents
and Settings\John\My Documents\use.pl line 12.
Bareword "priority" not allowed while "strict subs" in use at C:
\Documents and Settings\John\My Documents\use.pl line 12
.
Maye you thought that just manually adding use strict and use warnings
made things right?
Post real code.
Finally, how can you expect to get each item if you don't store the data
while you loop over your data?
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: 21 Nov 2006 08:36:19 -0800
From: "drood" <pws5252@gmail.com>
Subject: Submit buttons and param name
Message-Id: <1164126979.720980.155490@m73g2000cwd.googlegroups.com>
This allows a user to look for data on 2 different servers.
#########################
print submit(-name=>'choice', -value=>'Check Main Server ');
print "<br>";
print submit(-name=>'choice', -value=>'Check Local Server');
##########################
When I check which button is selected using:
#############################
foreach $name ( param() ) {
$value = param($name);
print "$name = $value<br>";
}
#############################
, I either get:
local = Check Local Server
or
main = Check Main Server
It seems the name of the param, local or main, is self generated. The
word 'main' and 'local' do not appear in the program.
What's the deal?
------------------------------
Date: 21 Nov 2006 10:18:23 -0800
From: "deadpickle" <deadpickle@gmail.com>
Subject: Using a variable in a matching string
Message-Id: <1164133103.273630.17350@j44g2000cwa.googlegroups.com>
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
------------------------------
Date: Tue, 21 Nov 2006 12:57:25 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: using an array to set up hash keys
Message-Id: <x7k61od6nu.fsf@mail.sysarch.com>
>>>>> "BM" == Brian McCauley <nobull67@gmail.com> writes:
BM> On Nov 21, 1:05 am, "John W. Krahn" <some...@example.com> wrote:
>> my %hash;
>> @hash{ @array } = ( 1 ) x @array;
>>
>> my %hash = map { $_ => 1 } @array;
>>
>> my %hash;
>> $hash{ $_ } = 1 for @array;
BM> Don't forget
BM> $_ = 1 for @hash{ @array };
and if you will use exists to check for a key or know the keys are all true:
@hash{ @array } = @array;
only exists works with this . i think this is the fastest and i uses the
least ram. AKAIK missing hash values are marked with a flag and not a
full SV of undef. easily checked with a devel:: module so i leave that
as an exercise to the reader.
@hash{ @array } = () ;
of course you have to declare my %hash for both of those.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
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 9993
***************************************