[17410] in Perl-Users-Digest
Perl-Users Digest, Issue: 4830 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 7 11:05:30 2000
Date: Tue, 7 Nov 2000 08:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973613110-v9-i4830@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 7 Nov 2000 Volume: 9 Number: 4830
Today's topics:
Re: Deparse error (M.J.T. Guy)
Failure / I don't know why ... <Christian.Oehring@de.bosch.com>
Re: Getting program line number? <dave@dave.org.uk>
Help -- msgget with key >= 0x80000000 fails <geoff-at-farmline-dot-com@127.0.0.1>
Re: Help again needed (not so ambitious this time) :-) <ren.maddox@tivoli.com>
Help! Can't use "next LABEL" in SIG{ALRM} sub <a@b.c>
Re: How can I sent a GIF to the browser <newsposter@cthulhu.demon.nl>
Re: Monitoring PIDs <ren.maddox@tivoli.com>
Re: Monitoring PIDs <nickco3@yahoo.co.uk>
Re: Perl and mysql <hartleh1@westat.com>
Re: Problem reading a binary file (Martien Verbruggen)
Re: Problem reading a binary file <mjcarman@home.com>
Re: Problem reading a binary file <james@NOSPAM.demon.co.uk>
Re: Problem reading a binary file <flavell@mail.cern.ch>
Re: Problems Downloading a Web Page REMOVEdino@texas.net
Re: Q: Getting program line number? <jeffp@crusoe.net>
Re: Q: Getting program line number? (Gwyn Judd)
Re: Q: Getting program line number? (Martien Verbruggen)
Re: Q: Getting program line number? <james@NOSPAM.demon.co.uk>
Re: Q: Getting program line number? <jeffp@crusoe.net>
Quick short easy question donoddy@my-deja.com
Re: Quick short easy question (Clay Irving)
Re: Quick short easy question <hartleh1@westat.com>
Re: Sorting hash of hashes by value dhartsough@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 7 Nov 2000 15:10:00 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Deparse error
Message-Id: <8u9608$gi4$1@pegasus.csx.cam.ac.uk>
Csaba Raduly <real.email@signature.this.is.invalid> wrote:
>C:\>perl -MO=Deparse text.pl
>Exiting subroutine via next at D:/usr/local/lib/perl5/5.6.0/os2/B/Deparse.pm
>line 257.
>Exiting subroutine via next at D:/usr/local/lib/perl5/5.6.0/os2/B/Deparse.pm
>line 257.
>Can't call method "sibling" on an undefined value at
>D:/usr/local/lib/perl5/5.6.0/os2/B/Deparse.pm line 257.
>CHECK failed--call queue aborted.
>Fragment of Deparse.pm:
>
>sub walk_sub {
> my $self = shift;
> my $cv = shift;
> my $op = $cv->ROOT;
> $op = shift if null $op;
> return if !$op or null $op;
> walk_tree($op, sub {
> my $op = shift;
> if ($op->name eq "gv") {
> my $gv = $self->maybe_padgv($op);
> if ($op->next->name eq "entersub") {
>Line 257-----> next if $self->{'subs_done'}{$$gv}++;
> next if class($gv->CV) eq "SPECIAL";
>Is this a problem with Deparse or did I make a mistake somewhere ?
In the current development Perl, those "next"s are all "return"s.
So yes, it's a bug in Deparse. Should be mended in 5.6.1.
Mike Guy
------------------------------
Date: Tue, 7 Nov 2000 15:11:00 +0100
From: Christian Oehring <Christian.Oehring@de.bosch.com>
Subject: Failure / I don't know why ...
Message-Id: <8u92hj$pen$1@proxy.fe.internet.bosch.de>
I have a File with the following structure Filename : dump.txt:
[User]
User1~UserDesc~Phone~
User2~UserDesc~Phone~
*
*
*
[Global]
GlobGroup1~GroupDesc~User1~User2~User3~
GlobGroup2~GroupDesc~User2~
GlobGroup3~GroupDesc~User2~User3~
*
*
*
[Local]
LocGroup1~GroupDesc~User2~
LocGroup2~GroupDesc~User2~User3~
LocGroup3~GroupDesc~User1~User2~User3~
than I have another File Filename users.txt
user1
user2
*
*
*
and at last I have a third file filename gruppen.txt
LocGroup3
*
*
*
And my perl script must generate a output file as following :
[User]
[Global]
[Local]
LocGroup1~GroupDesc~User2~
LocGroup2~GroupDesc~User2~
LocGroup3~GroupDesc~User1~User2~
For this task I have written the following Script
***************************************************
push (@groups,remove_enter($_));
}
# datei 1 durchgehen
while (<F1>)
{
# wenn Section-Marker...
if (substr($_,0,1) eq "[")
{
# ... Zeile ausgeben
print Fo $_;
# wenn Section=Local, dann $dodump auf 1, ansonsten auf 0
if (substr($_,0,7) eq "[Local]")
{
$dodump=1;
}
else
{
$dodump=0;
}
}
# Wenn $dodump==1
elsif ($dodump)
{
$line=$_;
# Split an der 1. Tilde
($group,$groupdesc,$rest)=split(/\~/,$line,3);
# Prüfen der GroupList auf diese Group, wenn nicht vorhanden ...
if (!(grep(/$group/,@groups)))
{
# ... dann Zeile in einzelne Einträge splitten
$rest=remove_enter($rest);
@gusers=split(/\~/,$rest);
@newusers=();
$getline=0;
for (@gusers)
{
$user=$_;
if (grep(/$user/,@users))
{
push (@newusers,$user);
$getline=1;
}
}
if ($getline)
{
$user=join("~",@newusers);
print Fo "$group~$groupdesc~$user~\r\n";
}
}
}
}
sub remove_enter
{
my $ret=$_[0];
$ret=~s/\n//gi;
$ret=~s/\r//gi;
return $ret;
}
***************************************************
It works very fine when I do the task for Global section but not for the
local section. Does anybody see the failure ???
Thanx
Christian
------------------------------
Date: Tue, 7 Nov 2000 14:10:58 -0000
From: "Dave Cross" <dave@dave.org.uk>
Subject: Re: Getting program line number?
Message-Id: <8u92jk$ftv$1@taliesin.netcom.net.uk>
<nospam@our.site> wrote in message news:8u90hl$j95$1@icrf.news...
> This message has been posted by: Aengus Stewart
<aengus.stewart@REMOVE-THIS-TO-SENDicrf.icnet.uk>
>
>
> In my program I want to do
>
> "Error at line number XXX"
>
> However I cant find a PERL global variable for this.
>
> I want this as my program parses a text results file and if the format
> of the results change I want a way that I can immediately spot where the
> parsing has broken and jump in and fix it.
>
> The PERL interpreter knows this info as it uses it in its diagnostic
> output.
>
> Apologies if this is something basic that I have missed, but I cant find
> a reference to it in the Programming Perl book or the man pages or the
> FAQs.
>
> Please dont tell me its a ".....download module Blobby from
> CPAN.........." :)
Aengus,
It's a little unclear exactly what you're asking, but I think you mean one
of two things.
If you want to report the line number in the Perl script where the error
occured then you can use the __LINE__ directive.
If you want to report the line number in the input file, then you should use
the $. (dollar dot) variable. This will work as long as you are processing
the file a line at a time.
hth,
Dave...
------------------------------
Date: Tue, 7 Nov 2000 14:15:12 -0000
From: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1>
Subject: Help -- msgget with key >= 0x80000000 fails
Message-Id: <8u92mh$hut$1@soap.pipex.net>
I want to use perl to access some IPC queues that are on a machine (Redhat
Linux 6.2, kernel 2.2.14, perl v5.005_03) I'm using. When I use
$IPC_CREAT=oct (1000);
$rq_queue=msgget (3774865663, $IPC_CREAT | oct(777));
$rt_queue=msgget (4292935648, $IPC_CREAT | oct(777));
it fails.
(3774865663 is 0xe0ffe0ff, 4292935648 is 0xffe0ffe0, two queues which
already exist on the system)
What I actually get is
> ipcs
------ Message Queues --------
key msqid owner perms used-bytes messages
0x80000000 1538 root 777 0 0
Now if I knock off the top bit from these numbers, and use 0x60ffe0ff and
7fe0ffe0 respectively, the queues are created correctly -- so I'm guessing
there's something up with signed and unsigned numbers.
Has anyone got a workaround for this? I'm loath to go messing around
changing large amounts of already-existing (and working!) C code...
Cheers
Geoff
------------------------------
Date: 07 Nov 2000 09:26:33 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Help again needed (not so ambitious this time) :-)
Message-Id: <m3puk7st06.fsf@dhcp11-177.support.tivoli.com>
"Michael Guenther" <MiGuenther@lucent.com> writes:
> >while(<TEST>) {
> > chomp;
> > my($first_name, $middle_initial, $last_name) = split /\|/;
> > print "Hi, my name is $first_name $middle_initial $last_name\n";
> >}
>
>
> As cool as it is to work with implicit variables
It's not about coolness. It's about clean, easy-to-read code. Using
an extra variable unnecessarily adds to complexity. Looping over the
lines of a file is such a common feature of Perl scripts that there is
no need for an explicit loop variable.
That doesn't mean that there aren't times when a loop variable is
helpful. In particular, if the loop is very large, or contains other
flow control structures (eg. another loop), then an explicit loop
variable is not only clarifying, it can even invaluable.
> http://www.perl.com/pub/doc/manual/html/pod/perlstyle.html
The only relevant point that I could find on this page was:
Similarly, just because an operator lets you assume default
arguments doesn't mean that you have to make use of the
defaults. The defaults are there for lazy systems programmers
writing one-shot programs. If you want your program to be
readable, consider supplying the argument.
While this is certainly a valid point, it doesn't say to *always* use
explicit arguments. To (hopefully) demonstrate that we are really
just discussing various degrees of this issue, consider "split". If
you don't want to use any implicit arguments, then you will need to
change the above split call to:
split /\|/, $_, 0;
or
split /\|/, $line, 0;
if using $line as the loop variable. The point is that the LIMIT
argument is also optional, but I doubt very many people would
recommend including the default LIMIT value of 0 on every split that
doesn't use a different value.
Allowing the $_ argument to be implicit when it is natural to do so is
simply part of Perl.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 7 Nov 2000 14:44:35 -0000
From: "Kingsley Tart" <a@b.c>
Subject: Help! Can't use "next LABEL" in SIG{ALRM} sub
Message-Id: <VzUN5.82662$hk2.202810@news6-win.server.ntlworld.com>
I'm trying to abort a loop on timeout with a SIG alarm but it won't use my
label. I've simplified the code here for testing purposes but the essense of
the SIG alarm is the same:
#!/usr/bin/perl
$counter=1;
CHECK: while ( $counter > 0 )
{
print "Trying ...\n";
$SIG{ALRM} = sub { print "timed out\n"; next CHECK; };
alarm (5);
$counter--;
sleep (10);
}
print "normal exit ...\n";
I was hoping that during the sleep statement, the SIG alarm would cause that
copy of the loop to finish and go back to the label but it doesn't recognise
the label, see below:
[kingsley@thorin perl]$ ./test4
Trying ...
timed out
Label not found for "next CHECK" at ./test4 line 6.
[kingsley@thorin perl]$
If I forget the SIG alarm and put "next CHECK;" into the loop, it recognises
the label. Am I trying to do the impossible?
--
Cheers,
Kingsley
k ingsl ey at sk 4 y mark 3 et dot 34 co dot 4 uk (remove the digits)
------------------------------
Date: 7 Nov 2000 15:48:53 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: How can I sent a GIF to the browser
Message-Id: <8u9895$hqr$3@internal-news.uu.net>
Frank Schlicht <fschlicht@tourisline.de> wrote:
> open(DATEI, "bild.gif");
You're not checking whether the open succeeded here.
Erik
------------------------------
Date: 07 Nov 2000 00:24:39 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Monitoring PIDs
Message-Id: <m3itq0l2oo.fsf@dhcp11-177.support.tivoli.com>
David McMullen <davidmac@austin.rr.com> writes:
> I am trying to monitor a process and have it notify me when it is
> finished. I'm either missing something or close and don't know it. Any
> help is appreciated.
Doing this by watching ps is arguably not the best choice. Having
said that, I'll assume that it is good enough for your needs.
> $i = (system "ps -ef | grep find | grep -v grep")
> print $i
>
> returns 0 while process is running and 256 when it is not running.
> What is the best way to monitor the process.
From perlfunc(1):
system LIST
...
The return value is the exit status of the program
as returned by the "wait" call. To get the actual
exit value divide by 256. See also the exec entry
elsewhere in this document. This is not what you
want to use to capture the output from a command,
for that you should use merely backticks or
"qx//", as described in the section on "`STRING`"
in the perlop manpage. Return value of -1
indicates a failure to start the program (inspect
$! for the reason).
Since grep returns 0 for a match and 1 for no match, you are getting
the correct output.
You can save yourself the trouble of calling two greps by letting Perl
do the searching for you. There are a number of ways to do this, but
for your purposes the easiest is probably something like:
sleep 1 while `ps -ef` =~ /\bfind\b/;
Note that I forced "find" to be a word. Your grep did not do that, so
if you want to remove it, just take the "\b"s out. Also, increasing
the sleep value to the largest value your willing to miss the end of
the process by would be friendly. And, of course, if another find is
running, all bets are off.
Also, depending on circumstances, you might be able to leave of the
"-e" option to find, which could be appreciably friendlier.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 07 Nov 2000 15:34:28 +0000
From: Nick Condon <nickco3@yahoo.co.uk>
Subject: Re: Monitoring PIDs
Message-Id: <3A082104.8A9256FA@yahoo.co.uk>
David McMullen wrote:
> $i = (system "ps -ef | grep find | grep -v grep")
> print $i
>
> returns 0 while process is running and 256 when it is not running.
> What is the best way to monitor the process.
Use backticks instead of system, that way $i will contain the STDOUT of your
command instead of the system return code, which is what you are getting at
the moment.
Or open with a pipe:
open (INPUT, "ps -ef | grep find | grep -v grep |")
while (<INPUT>) {
# do something
}
------------------------------
Date: Tue, 07 Nov 2000 10:43:12 -0500
From: Henry Hartley <hartleh1@westat.com>
Subject: Re: Perl and mysql
Message-Id: <3A082310.8754162E@westat.com>
vivekvp wrote:
>
> I am not very familiar with perl let alone mysql.
>
> What I am trying to do is create an html form that gets, a unique ID,
> name, phone number and email - store that data, and be able to retrieve
> that data via any query.
>
> But I am not sure what any syntax would be used? How do I pass the
> data? How do I retrieve it?
>
> Any help or direction?
1) Become familiar with Perl.
a) Get a copy and install it on your machine
b) Read the documentation
i) At a command prompt type "perldoc perl" (without the
quotes).
ii) Using perldoc, read all the other sections listed
c) Read posts to this newsgroup for one month (at least)
d) Get a book and read it. Try the examples.
e) Try things. Have fun.
2) Become familiar with MySQL.
a) Install MySQL on your machine
b) Read the documentation that comes with it
c) Create a database and try things. Have fun.
3) Become familiar with CGI.pm
a) Go to <http://stein.cshl.org/WWW/software/CGI/cgi_docs.html>
b) Read that document
c) Try things. Have fun.
4) Become familiar with DBI.pm
a) Go to <http://www.symbolstone.org/technology/perl/DBI/index.html>
b) Install the latest versions of the DBI module
and the MySQL DBD
b) Read the documentation for DBI and the MySQL DBD
c) Try things. Have fun.
5) Create an html form that gets, a unique ID, name,
phone number and email - store that data, and be
able to retrieve that data via any query
Hope that helps.
--
Henry Hartley
Westat
Rockville, Maryland, USA
------------------------------
Date: Wed, 8 Nov 2000 01:00:51 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Problem reading a binary file
Message-Id: <slrn90g2oj.boe.mgjv@martien.heliotrope.home>
On Tue, 7 Nov 2000 12:27:32 +0000,
James Taylor <james@NOSPAM.demon.co.uk> wrote:
> In article <8u8lvn$v3q$1@lublin.zrz.tu-berlin.de>, Anno Siegel
><URL:mailto:anno4000@lublin.zrz.tu-berlin.de> wrote:
>>
>> While I managed to remain in blissful ignorance of all things Windowish,
>> there's been enough mumble about binmode() in the group for me to mumble
>> along: You want binmode().
>
> When you say binmode(); in a program does it affect both
> STDIN and STDOUT simultaneously?
No. it affects nothing. And in fact, your program will exit with an
error.
# perl -e 'binmode()'
Not enough arguments for binmode at -e line 1, at end of line
Execution of -e aborted due to compilation errors.
if however, you invoke binmode() on a file handle, it only affects the
file handle you call it on. As documented in perlfunc. You can use the
open pragma if you want to set default modes; also hinted at in
perlfunc:binmode.
> Is the effect of binmode simply to turn off newline translation?
No. It does anything that is necessary on the system you're on to
facilitate the reading and writing of a binary file. Most often that
means, on some platforms, translation of \n to some external
representation of line termination. But other things may be necessary
(think of \cZ in DOS text files). On yet other systems it does nothing.
> If that is the case then for portability all file access that is
> not being processed as text should have binmode set, is that right?
Yes. Again, as per documentation:
In other words: Regardless of platform, use
binmode() on binary files, and do not use
binmode() on text files.
> What happens when a text file which has foreign newline characters
> is read without binmode set? Does Perl know how to convert all kinds
> of newline character combinations in the file to the "\n" kind in
> memory?
No. A text file with non-text characters is not a text file (but text
is more than just ASCII). If you tell Perl to read something in text
mode, it will do that. If the file is not text, you end up with garbage
in your variables.
The main thing that happens (in text mode) is that operating system
specific line terminators get translated to the single character "\n"
internally, and that any character sequences that terminate the file
actually signify eof() (even if the file was actually longer than that).
If, for example, you put a DOS text file on a Unix system, and read it
in text mode, you'll notice that each line ends in a \cM. Perl does not
know, nor should it, that this file originated on DOS and should
therefore be treated differently. It assumes that you know what you're
doing when you open it in text mode.
But even then, you can change the record separator that perl looks for.
Perl is more clever than you think.
Anyway, all this is firmly and clearly documented in perlfunc and
perlvar.
Martien
--
Martien Verbruggen |
Interactive Media Division | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd. | selective about its friends.
NSW, Australia |
------------------------------
Date: Tue, 07 Nov 2000 08:06:31 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Problem reading a binary file
Message-Id: <3A080C67.A2A512FE@home.com>
[Note: All of this is in the docs...]
James Taylor wrote:
>
> Anno Siegel wrote:
> >
> > You want binmode().
>
> When you say binmode(); in a program does it affect both
> STDIN and STDOUT simultaneously?
No, binmode() only affects the filehandle you apply it to.
> Is the effect of binmode simply to turn off newline translation?
For the most part, but it also allows you to read past a ^Z in a file.
In text mode that would be seen as an EOF. Calling binmode() on a file
means that you want the file's data exactly as it appears.
> If that is the case then for portability all file access that is
> not being processed as text should have binmode set, is that right?
For portability, always binmode() binary files, never binmode() text
files.
> What happens when a text file which has foreign newline characters
> is read without binmode set?
Most likely, nothing. For example, you can read a DOS file in Unix
without much difficulty, but you need to strip the ^M on your own.
> Does Perl know how to convert all kinds of newline character
> combinations in the file to the "\n" kind in memory?
Perl knows how to convert the platform's idea of "\n" to it's own
internal representation. In reality, "\n" is *not* a character. Think of
it as a "virtual newline character" which gets translated to/from the
real newline sequence on I/O.
-mjc
------------------------------
Date: Tue, 7 Nov 2000 14:35:44 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Problem reading a binary file
Message-Id: <ant0714441cbfNdQ@oakseed.demon.co.uk>
In article <slrn90g2oj.boe.mgjv@martien.heliotrope.home>, Martien Verbruggen
<URL:mailto:mgjv@tradingpost.com.au> wrote:
>
[snip lots of clear explaination of binmode, thanks]
>
> Anyway, all this is firmly and clearly documented in perlfunc and
> perlvar.
Yes, I felt a bit guilty about that after I posted the question,
but despite this you came through for me again. Thanks muchly...
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Tue, 7 Nov 2000 16:04:38 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Problem reading a binary file
Message-Id: <Pine.GHP.4.21.0011071601590.25758-100000@hpplus03.cern.ch>
On Tue, 7 Nov 2000, James Taylor wrote:
> > Anyway, all this is firmly and clearly documented in perlfunc and
> > perlvar.
>
> Yes, I felt a bit guilty about that after I posted the question,
If you're looking not only to write portable code, but also to process
foreign text formats (i.e text that has come in binary from some
platform that uses incompatible text formats) then you could start
with a look at the perlport documentation (where it discusses newline
formats and sockets programming), and then have a look at some of the
ingenious trickery found in CGI.pm.
------------------------------
Date: Tue, 07 Nov 2000 14:28:17 GMT
From: REMOVEdino@texas.net
Subject: Re: Problems Downloading a Web Page
Message-Id: <3a080f4b.427221642@corp.supernews.com>
I have a file called "Protocol" in the winnt dir. I've tried placing
copies of it in the dir containing my Perl script, but still no
success. I've also tried using Lynx. The script gives my the "die"
error which appears to be formatted correctly.
Lynx script as follows:
#GetHtml
$text_data = "d:\\lynx\\lynx.exe -cfg=d:\\lynx\\lynx.cfg -dump
\"http://www.perl.com\"";
#PrintHtml
$logfile=$text_data;
open(LOGFILE,"$logfile") || die "Error - could not open $logfile for
reading\n";
$linenum = 0;
while (<LOGFILE>) {
$linenum++;
print "$linenum:$_";
}
Protocol file as follows:
# Copyright (c) 1993-1995 Microsoft Corp.
#
# This file contains the Internet protocols as defined by RFC 1060
# (Assigned Numbers).
#
# Format:
#
# <protocol name> <assigned number> [aliases...] [#<comment>]
ip 0 IP # Internet protocol
icmp 1 ICMP # Internet control message protocol
ggp 3 GGP # Gateway-gateway protocol
tcp 6 TCP # Transmission control protocol
egp 8 EGP # Exterior gateway protocol
pup 12 PUP # PARC universal packet protocol
udp 17 UDP # User datagram protocol
hmp 20 HMP # Host monitoring protocol
xns-idp 22 XNS-IDP # Xerox NS IDP
rdp 27 RDP # "reliable datagram" protocol
rvd 66 RVD # MIT remote virtual disk
On 4 Nov 2000 11:55:29 -0000, Jonathan Stowe <gellyfish@gellyfish.com>
wrote:
>On Fri, 03 Nov 2000 15:12:12 GMT REMOVEdino@texas.net wrote:
>> I am trying to learn Perl and the first thing I wanted to do was
>> download a Web page. The following:
>>
>> use LWP::Simple;
>> getprint 'http://www.perl.com';
>>
>> returns 500 Can't connect to http://www.perl.com:80 (Bad protocol
>> 'tcp')
>>
>> I'm using Active States's Win32 build on a Win NT networked machine.
>
>
>you are missing your 'protocols' file which should be in somewhere in your
>%WINDIR% - you will need to have at least :
>
>ip 0 IP # internet protocol, pseudo protocol number
>icmp 1 ICMP # internet control message protocol
>tcp 6 TCP # transmission control protocol
>udp 17 UDP # user datagram protocol
>
>In it I would say. If you have difficulty determining where the file
>should be or how you would create it you would be better off asking in
>some newsgroup that discusses the NT operating system.
>
>I think the behaviour of the Win32 port changed between the 5* and 6* builds.
>
>/J\
>--
>Jonathan Stowe |
><http://www.gellyfish.com> | This space for rent
> |
------------------------------
Date: Tue, 7 Nov 2000 09:14:42 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Q: Getting program line number?
Message-Id: <Pine.GSO.4.21.0011070914130.25313-100000@crusoe.crusoe.net>
On Nov 7, Greg McCarroll said:
>On Tue, 07 Nov 2000, Aengus Stewart wrote:
>>
>>However I cant find a PERL global variable for this.
>
>there may be a better way to do this (although there is definetly a
>better syntax/golf way to do this) ...
print "This is line ", __LINE__, " of ", __FILE__, "\n";
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Tue, 07 Nov 2000 14:17:49 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Q: Getting program line number?
Message-Id: <slrn90g3ob.g2c.tjla@thislove.dyndns.org>
I was shocked! How could nospam@our.site <nospam@our.site>
say such a terrible thing:
>
>"Error at line number XXX"
>
>However I cant find a PERL global variable for this.
>
>I want this as my program parses a text results file and if the format
>of the results change I want a way that I can immediately spot where the
>parsing has broken and jump in and fix it.
Do you mean the line number in the Perl program or in the text file you
are parsing? If the latter then use the $. global variable. All the
global variables are listed in the 'perlvar' manual page
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
An INK-LING? Sure -- TAKE one!! Did you BUY any COMMUNIST UNIFORMS??
------------------------------
Date: Wed, 8 Nov 2000 01:16:03 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Q: Getting program line number?
Message-Id: <slrn90g3l3.boe.mgjv@martien.heliotrope.home>
On Tue, 07 Nov 2000 13:36:52 +0000,
nospam@our.site <nospam@our.site> wrote:
> This message has been posted by: Aengus Stewart <aengus.stewart@REMOVE-THIS-TO-SENDicrf.icnet.uk>
>
>
> In my program I want to do
>
> "Error at line number XXX"
>
> However I cant find a PERL global variable for this.
Perl. Perl. Perl. Perl. Perl. Perl. Perl.
or perl if you talk about the program. If you want to program in it,
please get used to spelling the name correctly.
Check the FAQ, section 1, if you don't believe me. On this newsgroup,
there is no such thing as PERL. On the stock markets there is, but
that's not where we are.
> I want this as my program parses a text results file and if the format
> of the results change I want a way that I can immediately spot where the
> parsing has broken and jump in and fix it.
The perlvar documentation describes the variable $., also known as
$INPUT_LINE_NUMBER, which I think might be what you want. However, why
don't you just keep track of the line number yourself? Using builtins is
good, but not always best.
> The PERL interpreter knows this info as it uses it in its diagnostic
> output.
Are you talking about the line number in a file you're reading ($.), or
do you want the current line in your program (__LINE__)?
> Apologies if this is something basic that I have missed, but I cant find
> a reference to it in the Programming Perl book or the man pages or the
> FAQs.
The perlvar documentation contains $., perlsyn contains one vague
reference to __LINE__, The camel has __LINE__ in its index, with
references to pages 68 and 618 (44 in version 2), and $. on 665 (132,
403 in version 2)
Martien
--
Martien Verbruggen |
Interactive Media Division | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd. | selective about its friends.
NSW, Australia |
------------------------------
Date: Tue, 7 Nov 2000 14:41:24 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Q: Getting program line number?
Message-Id: <ant071424b49fNdQ@oakseed.demon.co.uk>
In article <Pine.GSO.4.21.0011070914130.25313-100000@crusoe.crusoe.net>,
Jeff Pinyan <URL:mailto:jeffp@crusoe.net> wrote:
>
> print "This is line ", __LINE__, " of ", __FILE__, "\n";
Is there a similar way to get the error line number when you have
wrapped a large chunk of code in an eval to trap errors?
$@ seems to only contain the error message without the line number.
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Tue, 7 Nov 2000 11:02:37 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Q: Getting program line number?
Message-Id: <Pine.GSO.4.21.0011071058280.25313-100000@crusoe.crusoe.net>
On Nov 7, James Taylor said:
>In article <Pine.GSO.4.21.0011070914130.25313-100000@crusoe.crusoe.net>,
>Jeff Pinyan <URL:mailto:jeffp@crusoe.net> wrote:
>>
>> print "This is line ", __LINE__, " of ", __FILE__, "\n";
>
>Is there a similar way to get the error line number when you have
>wrapped a large chunk of code in an eval to trap errors?
>$@ seems to only contain the error message without the line number.
Really?
#!/usr/bin/perl
eval {
print 1 / $x;
};
print "error: $@";
__END__
error: Illegal division by zero at eval line 4.
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Tue, 07 Nov 2000 14:52:01 GMT
From: donoddy@my-deja.com
Subject: Quick short easy question
Message-Id: <8u94uf$g1i$1@nnrp1.deja.com>
Hi!
I would like to modify this line of my script:
print "<A HREF=\"$advert_url\">";
so it opens the link in a new window. Is this
the correct way to do it:
print "<A HREF=\"$advert_url\" target=\"_top\">";
I'm completly new to perl thats why this question is a bit
silly.
Any help is REALLY appriciated!
Donald
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 7 Nov 2000 15:19:11 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: Quick short easy question
Message-Id: <slrn90g7bf.bq7.clay@panix2.panix.com>
On Tue, 07 Nov 2000 14:52:01 GMT, donoddy@my-deja.com <donoddy@my-deja.com>
wrote:
>I would like to modify this line of my script:
>
>print "<A HREF=\"$advert_url\">";
>
>so it opens the link in a new window. Is this
>the correct way to do it:
>
>print "<A HREF=\"$advert_url\" target=\"_top\">";
>
>
>I'm completly new to perl thats why this question is a bit
>silly.
That's ok -- It isn't a Perl question anyway... You need help with HTML.
--
Clay Irving <clay@panix.com>
Yesterday I told a chicken to cross the road. It said, what for?
- Steven Wright
------------------------------
Date: Tue, 07 Nov 2000 10:24:30 -0500
From: Henry Hartley <hartleh1@westat.com>
Subject: Re: Quick short easy question
Message-Id: <3A081EAE.4B4D5A90@westat.com>
donoddy@my-deja.com wrote:
>
> Hi!
>
> I would like to modify this line of my script:
>
> print "<A HREF=\"$advert_url\">";
>
> so it opens the link in a new window. Is this
> the correct way to do it:
>
> print "<A HREF=\"$advert_url\" target=\"_top\">";
>
> I'm completly new to perl thats why this question is a bit
> silly.
So new to Perl, in fact, that you didn't notice that this question is
about HTML.
But, on a Perl subject, I'd have written that line like this to avoid
having to escape the " within the line:
print qq|<A HREF="$advert_url" target="new_window_name">| ;
--
Henry Hartley
Westat
Rockville, Maryland, USA
------------------------------
Date: Tue, 07 Nov 2000 14:11:57 GMT
From: dhartsough@my-deja.com
Subject: Re: Sorting hash of hashes by value
Message-Id: <8u92j8$e6a$1@nnrp1.deja.com>
In article <8u7er3$h9l$2@bmerhc5e.ca.nortel.com>,
msoulier@nortelnetworks.com wrote:
> In article <8u7bjf$2pn$1@nnrp1.deja.com>, dhartsough@my-deja.com
wrote:
> >...However, I do not see how to sort a hash of hashes
> > (or hash of hash of hashes...) by value returning
> >an ordered list of pairs of keys. Any help greatly appreciated...
>
> Hmm. Interesting. I don't see a problem though.
>
> @list = ();
>
> foreach my $key1 (keys %hash) {
> foreach my $key2 (keys %{ $hash{$key1} }) {
> push @list, "$key1 $key2";
> }
> }
> @list = sort @list;
>
> Was this even close to what you were after? ;-)
>
> Mike
>
OK, I can see from the replies that I did an incredibly poor job of
explaining the problem. Let me try again with an example (I apologize
for the brevity of the earlier question, it is obvious to me what I
wanted so it must be obvious to everybody else...). Anyway, if I have
the hash of hashes shown below:
my %hash = (
france => {
red => "12.72",
blue => "1.65",
green => "3.94",
},
germany => {
red => "6.47",
blue => "3.65",
green => "9.45",
},
italy => {
red => "2.22",
blue => "19.5",
green => "0.63",
},
);
I want to sort the keys by value and get back a list of hash keys in
pairs sorted by the order of the values they reference (e.g. italy,
green, france, blue, italy, red, germany, blue, france, green,... the
first pair of keys "italy", "green" references the value 0.63, the next
pair "france", "blue" references the value 1.65 ...). I can accomplish
this by creating a one-dimensional hash using a compound key formed by
a join on the original keys and then a split on the result:
foreach $key_1(keys %hash){
foreach $key_2(keys %{$hash{$key_1}}){
$cmpd_key = join ':',$key_1,$key_2;
$cmpd_hash{$cmpd_key} = $hash{$key_1}{$key_2};
}
}
@ord_list = sort{$cmpd_hash{$a} <=> $cmpd_hash{$b}} keys %cmpd_hash;
foreach $key (@ord_list){
($key_1,$key_2) = split(/:/,$key);
...now do other stuff I really want to do with $key_1 and $key_2...
}
The above works and gives me what I want, but seems to be a very non-
Perlish and inefficient solution. I am looking for something that will
sort by value acting directly on the multi-dimensional hash, rather
than compressing it down to a one-dimensional version. As always, any
help greatly appreciated...
dave
> --
> Michael P. Soulier, TD12, SKY Tel: 613-765-4699 (ESN: 39-54699)
> Optical Networks, Nortel Networks, SDE Pegasus
> "...the word HACK is used as a verb to indicate a massive amount
> of nerd-like effort." -Harley Hahn, A Student's Guide to UNIX
> Nortel Linux User's Group Ottawa: (internal) http://nlug.ca.nortel.com
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4830
**************************************