[18383] in Perl-Users-Digest
Perl-Users Digest, Issue: 551 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 23 00:05:45 2001
Date: Thu, 22 Mar 2001 21:05:14 -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: <985323914-v10-i551@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 22 Mar 2001 Volume: 10 Number: 551
Today's topics:
"perldoc" broken in Solaris 8 (Ben Okopnik)
[MySQL/DBI] Duplicate rows. <danni@progressiveideas.org>
Announce: Tk based alarm clock <sun_tong_001@yahoo.com>
Re: binary files <goldbb2@earthlink.net>
Creating array context <bjoern@hoehrmann.de>
Re: Creating array context (Abigail)
Re: Creating array context <bjoern@hoehrmann.de>
Re: Creating array context (Randal L. Schwartz)
Re: Creating array context <uri@sysarch.com>
Re: h2xs & typemap issue <david_no_spam@carter.net>
Re: How do I set disk space to be used by a group not a <mjcarman@home.com>
is there a way too.. <mrmead@canada.com>
Re: is there a way too.. (Tim Hammerquist)
Less greedy ??? <hafateltec@hotmail.com>
Re: Less greedy ??? <mjcarman@home.com>
MySQL / DBI Problem Danni
Novice user can't get search and replace to work <daniel_gregory@hotmail.com>
Re: Novice user can't get search and replace to work (Todd H.)
Re: Novice user can't get search and replace to work <krahnj@acm.org>
Re: Novice user can't get search and replace to work (Jim Land)
Re: Novice user can't get search and replace to work <krahnj@acm.org>
Re: Print "tar" Success or Failure <whataman@home.com>
Read from file into hash <afried@mediaone.net>
Re: Read from file into hash <tony_curtis32@yahoo.com>
Re: Read from file into hash <mjcarman@home.com>
running perl on a local machine in win me <nerdy@lycosasia.com>
Shared memory problem <sruyle@quik.com>
Re: Still can't die with Tar <whataman@home.com>
Re: Use of uninitialized value in string??? <mjcarman@home.com>
Re: Use of uninitialized value in string??? <uri@sysarch.com>
Re: Weird(?) magic word for sh to invoke perl under Lin <hrlngrv@aol.com>
XS typemap for long long? <david_no_spam@carter.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Mar 2001 04:09:08 GMT
From: ben-fuzzybear@geocities.com (Ben Okopnik)
Subject: "perldoc" broken in Solaris 8
Message-Id: <slrn9bljiq.96.ben-fuzzybear@Loki.Thor>
Hi, all -
I've recently started working as a consultant for Sun Microsystems, and
in hacking around using the default Perl installation under Solaris 8, I
noticed that "perldoc" is highly broken: it does not have a "-q" option
(using it returns a failure/"usage" message, which lists all the
switches - no "-q" anywhere in sight.) The only "release" info that I
can find on the Solaris CDs is "February 2000"; the Perl version is,
IIRC (no NG access from there), 5.005_03. Replacing the "perldoc"
script with the one from my Linux laptop works fine (of course), and
adds "-q" functionality - but I'm very surprised to find it missing in
the first place.
Any suggestions for whom I should notify?
Ben Okopnik
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Strange women lying in ponds distributing swords is no basis for a system
of government. -- M. Palin
------------------------------
Date: Thu, 22 Mar 2001 20:03:47 -0600
From: "Daniel Wilson" <danni@progressiveideas.org>
Subject: [MySQL/DBI] Duplicate rows.
Message-Id: <99eare$o1f$1@news.tpi.pl>
I have a serious problem, probably due to my lack of experience with MySQL
and the DBI interface.
I am designing an Ad Serving Daemon in perl using MySQL for databases. The
Daemon forks to handle each request.
The adserver is currently sending 130+ Queries per second to MySQL and i am
getting a lot of duplicate entrees in the databases when i should only be
getting single entrees.
I was checking to see if the first UPDATE generated an error and if it did,
because it would normaly result in the error 'Table 'database.A$info[3]'
doesn't exist' but i found that occasionaly $sth->errstr will result in
'Lost connection to MySQL server during query' hence the if ($sth->errstr =~
/doesn\'t exist/)
Can anyone see the fault in the code below, or any ideas on how i can
optimise/improve this routeen.
if ($dbh->do("UPDATE A$info[3] SET views = views + 1 WHERE day = $mday AND
month = $month AND year = $year AND adid = $info[0]") <= 0) {
if ($sth->errstr =~ /doesn\'t exist/) {
$dbh->do("CREATE TABLE IF NOT EXISTS A$info[3] (day INTEGER, month INTEGER,
year INTEGER, adid INTEGER, views INTEGER, uviews INTEGER, clicks INTEGER,
spent DECIMAL(100,10))");
$dbh->do("INSERT INTO A$info[3] VALUES ($mday, $month, $year,
$info[0],1,$unique,0,$info[4])");
} elsif (! $sth->errstr) {
$dbh->do("INSERT INTO A$info[3] VALUES ($mday, $month, $year,
$info[0],1,$unique,0,$info[4])");
}
} else {
$dbh->do("UPDATE A$info[3] SET spent = spent + $info[4] WHERE day = $mday
AND month = $month AND year = $year AND adid = $info[0]");
$dbh->do("UPDATE A$info[3] SET uviews = uviews + $unique WHERE day = $mday
AND month = $month AND year = $year AND adid = $info[0]");
}}
------------------------------
Date: 22 Mar 2001 20:08:08 -0400
From: * Tong * <sun_tong_001@yahoo.com>
Subject: Announce: Tk based alarm clock
Message-Id: <sa83dc5xs7r.fsf@sun_tong_001.personal.yahoo.com>
* Tong * <sun_tong_001@yahoo.com> writes:
> I'm planing to write a Tk based alarm clock, and make it open source
> tool for the public.
Thanks everyone who helped me recently. Now is my pay back time. The
first release of my alarm clock is ready. Please give it a try and
give me some advice.
I've put it in my xpt project web:
http://xpt.sourceforge.net/tools/crossplatform/
Thanks
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
http://members.xoom.com/suntong001/
- All free contribution & collection
------------------------------
Date: Fri, 23 Mar 2001 01:12:43 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: binary files
Message-Id: <3ABAA3BC.84D9BBC2@earthlink.net>
Todd Smith wrote:
>
> Is there a way to convert any file (picture, mp3, text, or anything)
> to a binary file that I can read (with a bunch of 1's and 0's) and
> convert it back to the original file from the binary? A Perl module
> maybe?
Perhaps what you want is the vec function?
(1) Read your entire file into one long string.
(2) Examine and modify it using vec($longstring,$offset,1). You can
both read from and assign to this function.
(3) Write out your modified file.
Alternatively, you might want to convert from a binary string to a
string of ascii ones and zeros.
Here are a few ways:
$ascii01 = pack 'b*', unpack 'i*', $longstring;
$ascii01 = pack 'B*', unpack 'i*', $longstring;
for my $i (0..8*length $longstring-1) {
substr($ascii01, $i, 1) = vec($longstring, $i, 1);
}
To convert back:
$longstring = pack 'i*', unpack 'b*', $ascii01;
$longstring = pack 'i*', unpack 'B*', $ascii01;
for my $i (0..8*length $longstring-1) {
vec($longstring, $i, 1) = substr($ascii01, $i, 1);
}
--
The difference between theory and practice is that in theory, theory and
practice are identical, but in practice, they are not.
------------------------------
Date: Fri, 23 Mar 2001 00:36:00 +0100
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Creating array context
Message-Id: <3ac58bbd.51035364@news.bjoern.hoehrmann.de>
Hi,
Is there any way to create array or list context? For scalar context
there is scalar() but for array context I need to use someting like
@{[ <array context> ]}
Is this the only way?
TIA,
--
Björn Höhrmann ^ mailto:bjoern@hoehrmann.de ^ http://www.bjoernsworld.de
am Badedeich 7 ° Telefon: +49(0)4667/981028 ° http://bjoern.hoehrmann.de
25899 Dagebüll # PGP Pub. KeyID: 0xA4357E78 # http://learn.to/quote [!]e
-- If something is worth writing it is worth keeping --
------------------------------
Date: Thu, 22 Mar 2001 23:55:50 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Creating array context
Message-Id: <slrn9bl486.vno.abigail@tsathoggua.rlyeh.net>
Bjoern Hoehrmann (bjoern@hoehrmann.de) wrote on MMDCCLX September
MCMXCIII in <URL:news:3ac58bbd.51035364@news.bjoern.hoehrmann.de>:
`' Hi,
`'
`' Is there any way to create array or list context? For scalar context
`' there is scalar() but for array context I need to use someting like
`'
`' @{[ <array context> ]}
`'
`' Is this the only way?
scalar() exists because it's useful to create scalar context while
otherwise being in list context, for instance when assigning to
arrays, or as parameters to a function call.
Lists consists of scalars.
But what on earth for do you want to create a list in otherwise
scalar context? Does it make sense?
Abigail
--
package Z;use overload'""'=>sub{$b++?Hacker:Another};
sub TIESCALAR{bless\my$y=>Z}sub FETCH{$a++?Perl:Just}
$,=$";my$x=tie+my$y=>Z;print$y,$x,$y,$x,"\n";#Abigail
------------------------------
Date: Fri, 23 Mar 2001 03:01:18 +0100
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: Creating array context
Message-Id: <3ac9abcc.59242796@news.bjoern.hoehrmann.de>
* Abigail wrote in comp.lang.perl.misc:
>`' Is there any way to create array or list context? For scalar context
>`' there is scalar() but for array context I need to use someting like
>`'
>`' @{[ <array context> ]}
>`'
>`' Is this the only way?
>
>scalar() exists because it's useful to create scalar context while
>otherwise being in list context, for instance when assigning to
>arrays, or as parameters to a function call.
>But what on earth for do you want to create a list in otherwise
>scalar context?
I thought of something like
my $B = scalar @{[$user =~ m|[$comp]|g]} # [1] [2]
In scalar context this would return 'true' and I had no chance to count
the elements in the array.
[1] scalar() is superflous here
[2] Yes, I know 'do { $B++ if index $comp, substr $user,$_,1 } for 0..3'
would be faster
--
Björn Höhrmann ^ mailto:bjoern@hoehrmann.de ^ http://www.bjoernsworld.de
am Badedeich 7 ° Telefon: +49(0)4667/981028 ° http://bjoern.hoehrmann.de
25899 Dagebüll # PGP Pub. KeyID: 0xA4357E78 # http://learn.to/quote [!]e
-- If something is worth writing it is worth keeping --
------------------------------
Date: 22 Mar 2001 18:50:02 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Creating array context
Message-Id: <m1d7b92o85.fsf@halfdome.holdit.com>
>>>>> "Bjoern" == Bjoern Hoehrmann <bjoern@hoehrmann.de> writes:
Bjoern> I thought of something like
Bjoern> my $B = scalar @{[$user =~ m|[$comp]|g]} # [1] [2]
Simpler to go:
my $count = () = $user =~ m/[$comp]/g;
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Fri, 23 Mar 2001 04:31:35 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Creating array context
Message-Id: <x7bsqt2jiv.fsf@home.sysarch.com>
>>>>> "A" == Abigail <abigail@foad.org> writes:
A> Bjoern Hoehrmann (bjoern@hoehrmann.de) wrote on MMDCCLX September
A> MCMXCIII in <URL:news:3ac58bbd.51035364@news.bjoern.hoehrmann.de>:
A> `' Hi,
A> `'
A> `' Is there any way to create array or list context? For scalar context
A> `' there is scalar() but for array context I need to use someting like
A> `'
A> `' @{[ <array context> ]}
A> `'
A> `' Is this the only way?
A> But what on earth for do you want to create a list in otherwise
A> scalar context? Does it make sense?
besides that, so many operators and functions provide a list context
that is is rarely needed on its own. and as the docs say, a simple ()
will usually do otherwise.
so, why do you think you need this?
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 23 Mar 2001 03:16:07 GMT
From: "david carter" <david_no_spam@carter.net>
Subject: Re: h2xs & typemap issue
Message-Id: <Xdzu6.151183$__6.27834019@typhoon.southeast.rr.com>
Joe - thanks for taking time to look up that old post & pointing it out to
me. Yes, these are char arrays, so we're on the right track.
However, these are char arrays within structs, so Ilya's simple solution:
>> But the simplest thing may be to
>>
> >#define firstname char_pointer
> >typedef char *char_pointer;
>>
> >at the beginning of your XSUB...
>Oups, I meant "after including your header file" in your XS file.
doesn't work. gcc complains that: structure has no member named
'char_pointer'.
When my mind is not so tired, I'll give his typemap entry suggestion a try.
My c is a bit rusty, so it might be a challenge!
Thanks again,
David
"Joe Schaefer" <joe+usenet@sunstarsys.com> wrote in message
news:m3k85h31rp.fsf@mumonkan.sunstarsys.com...
> david_no_spam_@carter.net writes:
>
> > Getting the following errors while trying to compile a new XS module.
Occurs
> > for each "char" type in the input .h file:
>
> Aren't those char's really character arrays? I pulled up a Jan 22
> post by Ilya that might be of use:
>
>
http://groups.google.com/groups?hl=en&lr=&safe=off&ic=1&th=73687d7667a71b63&
seekd=936040096#936040096
>
> HTH
> --
> Joe Schaefer "I deal with temptation by yielding to it."
> --Mark Twain
------------------------------
Date: Thu, 22 Mar 2001 16:38:42 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: How do I set disk space to be used by a group not a user
Message-Id: <3ABA7EF2.B6F94EAD@home.com>
batespd wrote:
>
> I'm just passing message on for my son
> Point me in the direction of any suitable FAQ
Disk quotas have nothing to do with Perl, and are thus off-topic here. I
suggest taking your question to a newsgroup that deals with your
operating system and/or system administration.
-mjc
------------------------------
Date: Fri, 23 Mar 2001 01:36:36 GMT
From: "Mr. Man" <mrmead@canada.com>
Subject: is there a way too..
Message-Id: <EMxu6.34410$5P1.447052@news1.rdc1.ab.home.com>
I need to capture a cgi script from another web site is this possible?
------------------------------
Date: Fri, 23 Mar 2001 02:04:38 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: is there a way too..
Message-Id: <slrn9blc24.g2o.tim@vegeta.ath.cx>
Mr. Man <mrmead@canada.com> wrote:
> I need to capture a cgi script from another web site is this possible?
Does this sound suspicious to anyone else? ;)
Basically, if you were meant to have the script, it would be made
available to you.
--
-Tim Hammerquist <timmy@cpan.org>
scanf() is evil.
------------------------------
Date: Fri, 23 Mar 2001 10:30:03 +1000
From: "Michael R. McPherson" <hafateltec@hotmail.com>
Subject: Less greedy ???
Message-Id: <99e5ee02e0q@enews3.newsguy.com>
I need help to make this less greedy.
#!/usr/bin/perl -w
use strict;
use Net::Telnet ();
my $t = new Net::Telnet(Timeout => 10, #Create telnet object.
Prompt => '/sonata\.tel118\.\d{4}> $/');
$t->open("192.168.1.1") || die "Can't open 192.168.1.1";
$t->login(Name => 'www', #login to telnet session.
Password => 'www',
Prompt => '/sonata\.tel118\.\d{4}> $/',
Timeout => 10);
my $who = $t->cmd('who');
print $who;
My problem is this:
Prompt => '/sonata\.tel118\.\d{4}> $/',
--------------------------------^^
The \d{4} could change to only three digits or 1 or 5... This is where my
problem is but I am not sure how to correct it.
Any / all help is greatly appriciated.
--
##############Þ
print "\n Welcome to NEPP";$Þ=1;while ($Þ){
print "\n$Þ";$Þ++;if ($Þ == 1000) {
print "\n$Þ"."\nWell almost never ending :þ";exit;}}
##############Þ
------------------------------
Date: Fri, 23 Mar 2001 02:59:28 GMT
From: Michael Carman <mjcarman@home.com>
Subject: Re: Less greedy ???
Message-Id: <3ABABC69.299FE8AC@home.com>
"Michael R. McPherson" wrote:
>
> I need help to make this less greedy.
>
> My problem is this:
>
> Prompt => '/sonata\.tel118\.\d{4}> $/',
> --------------------------------^^
>
> The \d{4} could change to only three digits or 1 or 5...
> This is where my problem is but I am not sure how to correct
> it.
That's not greedy. The '\d{4}' says "match exactly four digit
characters." It won't match less or suck up more. How many digits
are you expecting?
\d* match 0 or more digits
\d+ match 1 or more digits
\d? match 0 or 1 digits
\d{2} match exactly two digits
\d{2,} match at least two digits
\d{1,5} match 1 to 5 digits
...
This is, of course, all well-documented in the perlre manpage.
-mjc
------------------------------
Date: 23 Mar 2001 01:38:22 GMT
From: Danni
Subject: MySQL / DBI Problem
Message-Id: <99e9ee2200a@news1.newsguy.com>
I have a serious problem, probably due to my lack of experience with MySQL and the DBI interface.
I am designing an Ad Serving Daemon in perl using MySQL for databases. The Daemon forks to handle each request.
The adserver is currently sending 130+ Queries per second to MySQL and i am getting a lot of duplicate entrees in the databases when i should only be getting single entrees.
I was checking to see if the first UPDATE generated an error and if it did, because it would normaly result in the error 'Table 'database.A$info[3]' doesn't exist' but i found that occasionaly $sth->errstr will result in 'Lost connection to MySQL server during query' hence the if ($sth->errstr =~ /doesn\'t exist/)
Can anyone see the fault in the code below, or any ideas on how i can optimise/improve this routeen.
if ($dbh->do("UPDATE A$info[3] SET views = views + 1 WHERE day = $mday AND month = $month AND year = $year AND adid = $info[0]") <= 0) {
if ($sth->errstr =~ /doesn\'t exist/) {
$dbh->do("CREATE TABLE IF NOT EXISTS A$info[3] (day INTEGER, month INTEGER, year INTEGER, adid INTEGER, views INTEGER, uviews INTEGER, clicks INTEGER, spent DECIMAL(100,10))");
$dbh->do("INSERT INTO A$info[3] VALUES ($mday, $month, $year, $info[0],1,$unique,0,$info[4])");
} elsif (! $sth->errstr) {
$dbh->do("INSERT INTO A$info[3] VALUES ($mday, $month, $year, $info[0],1,$unique,0,$info[4])");
}
} else {
$dbh->do("UPDATE A$info[3] SET spent = spent + $info[4] WHERE day = $mday AND month = $month AND year = $year AND adid = $info[0]");
$dbh->do("UPDATE A$info[3] SET uviews = uviews + $unique WHERE day = $mday AND month = $month AND year = $year AND adid = $info[0]");
}}
==================================
Posted via http://nodevice.com
Linux Programmer's Site
------------------------------
Date: Thu, 22 Mar 2001 15:57:29 -0800
From: "Daniel Gregory" <daniel_gregory@hotmail.com>
Subject: Novice user can't get search and replace to work
Message-Id: <#PzvVvysAHA.353@cpmsnbbsa07>
I am a novice perl user and attempting to get my script to do a search and
replace of a file. I am attempting to get the last modifed time of an asp
page to appear using a perl script prior to putting it on my web server. The
script runs but doesn't do any search and replace. Tried to look at it under
a perl debugger and I can see the file load but that is it.
Here is my script any help on what I am doing wrong would be great
#!/usr/bin/perl -wl
open (STATUS, "+<c:\\new_stuff.asp") || die "Can't open new_stuff.asp:
$!\n";
($sec,$min, $hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
%weekday=("0"=> "Sudnay",
"1"=> "Monday,",
"2"=> "Tuesday",
"3"=> "Wednesday",
"4"=> "Thursday",
"5"=> "Friday",
"6"=> "Saturday",
);
%month=("0" => "January",
"1" => "February",
"2" => "March",
"3" => "April",
"4" => "May",
"5" => "June",
"6" => "July",
"7" => "August",
"8" => "September",
"9" => "October",
"10" => "November",
"11" => "December",
);
$year += 1900;
$m = "am" ;
if ( $hour >= 12 ) { $hour -= 12 ; $m = "pm" ; }
$update = "<B>Last Updated</B><br>$weekday{$wday} $month{$mon}, $mday $year
at $hour:$min $m PST.<P>";
while (<STATUS>){
s/(<\B\>Last Updated<\/B\><\br\>*?);/$update/;
}
thanks
daniel
------------------------------
Date: 22 Mar 2001 21:01:50 -0600
From: comphelp@toddh.net (Todd H.)
Subject: Re: Novice user can't get search and replace to work
Message-Id: <ly3dc5i3xd.fsf@k2.onsight.com>
I'm far from a guru, but your query intrigued me.
"Daniel Gregory" <daniel_gregory@hotmail.com> writes:
> %weekday=("0"=> "Sudnay",
typo?
> while (<STATUS>){
> s/(<\B\>Last Updated<\/B\><\br\>*?);/$update/;
One thing that looks odd to me is that \B where you may actually want
to match the literal B. Likewise with the \br\> at the end.
Does this work instead (removing the \ before B and the b in br:
s/(<B\>Last Updated<\/B\><br\>*?);/$update/;
HTH...but I haven't tested it, so YMMV. :-)
--
Todd H.
http://www.toddh.net/
------------------------------
Date: Fri, 23 Mar 2001 03:29:54 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Novice user can't get search and replace to work
Message-Id: <3ABAC4AE.48D1DDFA@acm.org>
Daniel Gregory wrote:
>
> I am a novice perl user and attempting to get my script to do a search and
> replace of a file. I am attempting to get the last modifed time of an asp
> page to appear using a perl script prior to putting it on my web server. The
> script runs but doesn't do any search and replace. Tried to look at it under
> a perl debugger and I can see the file load but that is it.
>
> Here is my script any help on what I am doing wrong would be great
>
> #!/usr/bin/perl -wl
> open (STATUS, "+<c:\\new_stuff.asp") || die "Can't open new_stuff.asp:
> $!\n";
> ($sec,$min, $hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
> %weekday=("0"=> "Sudnay",
> "1"=> "Monday,",
> "2"=> "Tuesday",
> "3"=> "Wednesday",
> "4"=> "Thursday",
> "5"=> "Friday",
> "6"=> "Saturday",
> );
> %month=("0" => "January",
> "1" => "February",
> "2" => "March",
> "3" => "April",
> "4" => "May",
> "5" => "June",
> "6" => "July",
> "7" => "August",
> "8" => "September",
> "9" => "October",
> "10" => "November",
> "11" => "December",
> );
%weekday and %month should probably be arrays:
@weekday = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
@month = qw(January February March April May June July August September
October November December);
> $year += 1900;
> $m = "am" ;
> if ( $hour >= 12 ) { $hour -= 12 ; $m = "pm" ; }
If $hour equals 12 (noon) then subtract 12 leaving 0 (midnight)?
> $update = "<B>Last Updated</B><br>$weekday{$wday} $month{$mon}, $mday $year
> at $hour:$min $m PST.<P>";
>
> while (<STATUS>){
> s/(<\B\>Last Updated<\/B\><\br\>*?);/$update/;
^^^
Match zero or more '>' characters? You probably want >.*?
> }
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 23 Mar 2001 04:12:48 GMT
From: jland@bigfoot.com (Jim Land)
Subject: Re: Novice user can't get search and replace to work
Message-Id: <Xns906CE8583jlandbigfootcom@207.106.93.83>
Daniel,
Since you didn't tell us what's in your new_stuff.asp file, we don't know
what text you're searching for in the substitute... 8^(
But in general, I think you would do well to simplify your regex
substitution
s/(<\B\>Last Updated<\/B\><\br\>*?);/$update/;
in a little test script like this:
========================
$stringtext = "<B>Last Updated</B><br>blah blah blah<P>";
print "the string before substitution is $stringtext \n" ;
$stringtext =~ s/<B>Last Updated<\/B><br>/replacementtext/;
print "the string after substitution is $stringtext \n" ;
========================
Once this simplified version works properly, you can refine it.
------------------------------
Date: Fri, 23 Mar 2001 04:05:21 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Novice user can't get search and replace to work
Message-Id: <3ABACD07.B6E1B4C3@acm.org>
"John W. Krahn" wrote:
>
> [snip]
>
> > while (<STATUS>){
> > s/(<\B\>Last Updated<\/B\><\br\>*?);/$update/;
^^
I just noticed this. You are trying to match a backspace character (\b).
s/<B>Last Updated<\/B><br>.*?;/$update/i;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 23 Mar 2001 01:05:43 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Print "tar" Success or Failure
Message-Id: <3ABAA1E2.3A820ADD@home.com>
I lied about dev/null... I got dev/null to work. Try this and tell me
what you think. You gave me this idea, Benjamin. How is this method for
checking tar's failure of success?
#!/usr/bin/perl -wd
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";
$out = `tar -zxf success.tar.gz 3>&1 1>&2 2>&3 3>&-`;
if ( $out =~ "status" ) {
print "TAR OPERATION FAILED!<BR>$out\n";
} else {
print "SUCCESS!";
};
--Dennis
------------------------------
Date: Thu, 22 Mar 2001 20:20:38 -0600
From: Alan Friedman <afried@mediaone.net>
Subject: Read from file into hash
Message-Id: <3ABAB2F6.4BBAC09B@mediaone.net>
I have a text file with a pair of words separated by the "or" bar
on each line as follows:
Fruits|apple
Fruits|pear
Fruits|orange
Fruits|peach
Animals|cat
Animals|dog
Animals|mouse
Birds|sparrow
Birds|crow
Birds|cardinal
Car|Ford
etc.
I need to read in the pairs and assign them to a hash
as follows:
%thehash = ( "Fruits" => ["apple","pear","orange","peach"],
"Animals" => ["cat","dog","mouse"],
"Birds" => ["sparrow","crow","cardinal"],
"Car" => ["Ford"]
);
Thanks.
------------------------------
Date: 22 Mar 2001 20:55:42 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Read from file into hash
Message-Id: <87bsqtchxt.fsf@limey.hpcc.uh.edu>
>> On Thu, 22 Mar 2001 20:20:38 -0600,
>> Alan Friedman <afried@mediaone.net> said:
> I have a text file with a pair of words separated by the
> "or" bar on each line as follows:
> Fruits|apple
> ...
> I need to read in the pairs and assign them to a hash as
> follows:
> "Fruits" => ["apple","pear","orange","peach"]
> ...
my %cache;
while (<DATA>) {
chomp;
my ($key, $val) = split /\|/;
push @{$cache{$key}}, $val; # ain't perl fun?
}
use Data::Dumper;
print Dumper(\%cache);
__DATA__
Fruits|apple
... rest of data here
hth
t
--
Just reach into these holes. I use a carrot.
------------------------------
Date: Fri, 23 Mar 2001 03:05:15 GMT
From: Michael Carman <mjcarman@home.com>
Subject: Re: Read from file into hash
Message-Id: <3ABABDC4.B496EC5F@home.com>
Alan Friedman wrote:
>
> I have a text file with a pair of words separated by the "or" bar
> on each line as follows:
>
> Fruits|apple
> Fruits|pear
[snip]
>
> I need to read in the pairs and assign them to a hash
> as follows:
>
> %thehash = ( "Fruits" => ["apple","pear","orange","peach"],
> "Animals" => ["cat","dog","mouse"],
> "Birds" => ["sparrow","crow","cardinal"],
> "Car" => ["Ford"]
> );
Piece of cake; just split on the '|' and push the data onto your HoL:
#!/usr/local/bin/perl -w
use strict;
my %thehash;
while (<DATA>) {
chomp;
my ($key, $val) = split(/\|/, $_);
push(@{$thehash{$key}}, $val);
}
__DATA__
Fruits|apple
Fruits|pear
Fruits|orange
Fruits|peach
Animals|cat
Animals|dog
Animals|mouse
Birds|sparrow
Birds|crow
Birds|cardinal
Car|Ford
------------------------------
Date: Fri, 23 Mar 2001 09:43:36 +1000
From: "ckw" <nerdy@lycosasia.com>
Subject: running perl on a local machine in win me
Message-Id: <3aba8ebc_2@news01.one.net.au>
hi
how can i run perl on a local machine who's running win me?
can i use personal web server? or is there any other software which will
enable me to do so?
thanks
------------------------------
Date: Fri, 23 Mar 2001 02:35:01 GMT
From: sruyle <sruyle@quik.com>
Subject: Shared memory problem
Message-Id: <3ABADFCE.E15C6694@quik.com>
I have a problem trying to read a shared memory segment created in a C
program.
I can access it correctly in another C program.
In perl, however, It seems that i can correct to the correct segment,
but
cant read the data from it.
shmget attaches to the right segment, but shmread only returns nulls,
any idea?
the shared segment only contains a short int.
here is the perl code.
#!/usr/bin/perl
use IPC::SysV qw(IPC_CREAT IPC_RMID S_IRUSR S_IRGRP S_IROTH);
$SHM_ID =$ENV{CPU_LOAD_AVG_SHM_ID};
if ( ! $SHM_ID )
{
print STDERR "ERROR: Environment not configured\n";
print STDERR "CPU_LOAD_AVG_SHM_ID must be set\n";
exit;
}
print "SHM_ID is $SHM_ID\n";
$size = 2;
$key = shmget($SHM_ID, $size, IPC_CREAT | S_IRUSR | S_IRGRP |
S_IROTH ) || die "$!";
shmread($key, $buff, 0, 2) || die "$!";
print "shm key $key\n";
print "read buff: '$buff'\n";
printf " value = %4.4x\n", $buff;
$foo = unpack('s*', $buff);
print "read foo: '$foo'\n";
# print "deleting shm $key\n";
# shmctl($key, IPC_RMID, 0) || die "$!";
thanks in advance for any answers.
steve
------------------------------
Date: Thu, 22 Mar 2001 23:27:54 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Still can't die with Tar
Message-Id: <3ABA8AF5.F9B71271@home.com>
Benjamin Goldberg wrote:
>
> BUCK NAKED1 wrote:
> >
> [snip]
> > system("tar -zxf failure.tar.gz 2>&1");
>
> Hmm, I just noticed this... if you use the -z option to tar, and a .gz
> file, which means that tar must call on gzip to decompress the file.
>
> This complicates things and can cause problems.
>
Thank You. Everyone sounded like this shouldn't be that complicated, and
I didn't think so either; but this has got complicated and frustrating,
though perhaps interesting and informative.
>
> [snip]
> > Now, WHY is "SUCCESS: 0" printing whether the tar operation is
> > successful or fails?
>
> Gzip fails to find the file. It outputs an empty file, and returns an
> error code.
If gzip fails to find the file, why do I get different return values in
my test below? Isn't the problem with the return value of tar, not gzip?
> Tar sees the error code, but stupidly ignores it. It also
> sees that you are trying to unarchive an empty file. It decides that
> empty files are perfectly valid empty archives, and says to itself "Ok,
> nothing in the file. We sucessfully unarchived all 0 files," and then
> gives a 0 exit code, for having "succeeded" at unarchiving nothing.
>
Hmmm... still sounds like a "tar" problem, not a gzip problem.
So there's a problem with Tar and what it returns. Bart mentioned
something about "parsing" the results to get the success or failure, but
I don't know how. FWIW, I've been spending much time reviewing man tar.
[snip]
>
> If you run tar using open() with a pipe (a "|" at the beginning or
> end), you use close() to check the success.
>
Now, that's another way I had not thought of.
[snip]
>
> Return codes are found there[$?], yes, and these may represent errors. > But there're also errors printed to stderr, which you could also check.
>
How do I do that? I tried "print STDERR;" and also sending the values of
system to dev/null and got a blank page.
> The best thing to do, would be to test for the file's existance
> yourself, rather than relying on tar to do it for you. This is much
> faster, and will save you alot of grief. If you have made sure that the
> file does exist, then it's quite likely that tar's exit code (the value
> in $?) will be exactly what you expect it to be... 0 for success, and
> nonzero for failure.
>
> To see if file exists, simple use the -f operator.
> unless( -f "failure.tar.gz" ) {
> die "FAILURE";
> }
Thanks, I'll try this. It sounds like a good solution for checking a
"zip" operation, too. I was hoping to find the same solution for failure
or success of 'tar' or 'zip', if possible. This has become so
complicated and frustrating that I'm almost willing to abort a real
error message, and just check tar's results for an empty file , and
print "FAILED" based on an empty file.
As you'll see below, I can check the return of gzip and print success or
failure according to a different return value of $?, but tar still wants
to be difficult.
Here's a little test I ran that is interesting...
#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";
system("tar -x success.tar");
print "Tar Success returns a Value of $?";
print "<BR>";
system("tar -x failure.tar");
print "Tar Failure returns a Value of $?";
print "<BR><BR>";
system("gzip success.tar.gz");
print "Gunzip Success returns a Value of $?";
print "<BR>";
system("gzip failure.tar.gz");
print "Gunzip Failure returns a Value of $?";
print "<BR><BR>";
system("tar -zx success.tar.gz");
print "Tar w/-z Success returns a Value of $?";
print "<BR>";
system("tar -zx failure.tar.gz");
print "Tar w/-z Failure returns a Value of $?";
print "<BR><BR>";
OUTPUT...
Tar Success returns a Value of 768
Tar Failure returns a Value of 768
Gunzip Success returns a Value of 256
Gunzip Failure returns a Value of 512
Tar w/-z Success returns a Value of 0
Tar w/-z Failure returns a Value of 0
I've also tried printing the following per instructions from perldoc -f
system...
$exit_value = $? >> 8;
$signal_num = $? & 127;
$dumped_core = $? & 128;
Of course, these too return 0 whether tar -z is successful or not.
I can understand Gary's frustration. My head hurts too. Just so you
know, I have appreciated ALL of the responses, and am still reviewing
the thread for things I may have missed or misunderstood.
Regards,
--Dennis
------------------------------
Date: Thu, 22 Mar 2001 16:33:31 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Use of uninitialized value in string???
Message-Id: <3ABA7DBB.E833703E@home.com>
[Post reordered & trimmed.]
Bryan Coon wrote:
>
> Bryan Coon wrote:
>
>> Can someone please tell me what the heck I am doing wrong here?
[snip]
>> my $act = $query->param("act");
>> my $userid = $query->param("userid");
>>
>> if ($act eq '' && $userid eq '') {
>> #do some stuff
>> }
>>
>> This generates the following error:
>> Use of uninitialized value in string eq at /my/file/test.cgi line 13.
>> Use of uninitialized value in string eq at /my/file/test.cgi line 13.
>>
>> Why?? Neither $act or $userid is unitialized (right?)
Well, yes, but Perl actually throws that error on using an undefined
variable (in anything other than a boolean context), not based on
whether it has ever been seen on the left side of an assignment
operator.
In other words, $query->param("act") is returning undef.
> Sorry, little follow up here- all values from query are null, i.e. The
> script is being called by simple 'http://mysite/test.cgi', as opposed to
> 'http://mysite/test.cgi?jobid=32434&userid=939434 etc etc.
Yep. :)
> I want the script to do something when all query->params are empty...
Then you need to test for definedness. The empty string you're testing
for is a defined value. (Anything but undef is.)
unless (defined($act) && defined($userid)) {
# Do stuff
}
Actually, as long as you aren't worried about distinguising between
undefined and the defined false values (0, '0', and '') you can simplify
that to a boolean test:
unless ($act && $userid) {
# Do stuff
}
but you'll have to decide whether or not that's appropriate.
-mjc
------------------------------
Date: Fri, 23 Mar 2001 03:21:08 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Use of uninitialized value in string???
Message-Id: <x7elvp2mse.fsf@home.sysarch.com>
>>>>> "CM" == Ciaran McCreesh <ciaran.mccreesh@useaddressbelow.please> writes:
CM> In article <3ABA49F8.582BFB0D@sequenom.com> (whatever that means), Bryan
CM> Coon <bcoon@sequenom.com> writes
>> Can someone please tell me what the heck I am doing wrong here? (This
>> is the boiled down code btw)
CM> <snip>
>> if ($act eq '' && $userid eq '') {
CM> (($act eq '') && ($userid eq ''))
why do you think parens would help? && binds lower than eq because it
was designed to be used between compare ops. he problem is very simple,
he needs to test with defined first.
CM> HTH,
no it didn't.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 23 Mar 2001 01:10:26 GMT
From: "Harlan Grove" <hrlngrv@aol.com>
Subject: Re: Weird(?) magic word for sh to invoke perl under Linux
Message-Id: <6oxu6.741$9i1.47915@bgtnsc04-news.ops.worldnet.att.net>
Abigail <abigail@foad.org> wrote in ...
>* Tong * (sun_tong_001@yahoo.com) wrote on ...
>%% abigail@foad.org (Abigail) writes:
...
>%% > Then /usr/bin/env only works for those who have the correct path.
>%%
>%% yes, Abigail, but the normal situation is that the sys admin won't
>%% change anything for any personal requests. Setting my path correctly
>%% is far more easier than making them believe /usr/bin/perl is the
>%% right place for perl...
>
>Hmmm. So, setting the path correctly on all systems for all users under
>all circumstances (cron! -T!) is *easier* than setting #! once for each
>program on each system? Which you could do from 'make install' anyway?
...
The sysadmin would only do custom software installations into /usr/local or
/opt but would allow mere users to write generally available scripts?
Wouldn't it be FAR MORE LIKELY that this is an individual user writing
scripts for personal use? S/he does have to ensure her/his path is correct,
but if so, then getting the path right would be the way to go - allowing
individuals to put /usr/local/bin, /opt/bin or (Solaris-specific) the POSIX
bin directory before /usr/bin without affecting general stuff.
It should be obvious from the original post that the OP is running a script
in ~. Presumably ALL USERS wouldn't need access to it. Only ONE user would
need the appropriate path. Seems practical.
>As for that sysadmin, I am such a sysadmin. I do believe that
>/usr/bin/perl is the right place - for the perl that comes with the
>OS. The perl that's current, compiled with the available compiler and
>compiled with the options desired does live elsewhere. /opt/perl for
>instance. And guess what, that isn't in someones default $PATH.
...
You mean mere users can't modify their PATH in their own shell profile or rc
files? If people are smart enough to write scripts, wouldn't they be smart
enough to change PATH? Assuming neither . not ~/bin is in their default
path, they're either going to get very sick of typing ./ or similar before
every command or they're going to change their path.
------------------------------
Date: Fri, 23 Mar 2001 03:22:07 GMT
From: "david carter" <david_no_spam@carter.net>
Subject: XS typemap for long long?
Message-Id: <zjzu6.151290$__6.27844177@typhoon.southeast.rr.com>
h2xs default typemap for a "long long" is outputting code (within a struct
accessor routine) which raises this warning from gcc:
>warning: cast to pointer from integer of different size
I suspect that this is not the behavior I want.
Anyone out there know the proper way to deal with 64-bit integers in a
platform-independent manner in XS?
Thanks,
David
------------------------------
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 V10 Issue 551
**************************************