[7458] in Perl-Users-Digest
Perl-Users Digest, Issue: 1084 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 26 10:07:19 1997
Date: Fri, 26 Sep 97 07:01:52 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 26 Sep 1997 Volume: 8 Number: 1084
Today's topics:
printing variables... (Michele Beltrame)
printing variables... (Michele Beltrame)
Re: printing variables... <eike.grote@theo.phy.uni-bayreuth.de>
Re: processing variable input variables <rootbeer@teleport.com>
Re: Question: How to generate same "random" numbers... <godfrey@hnashe.com>
Re: Read AND WRITE dBASE files from Perl <seay@absyss.fr>
Regular expression <claus@selle.com>
Re: Regular expression (Tad McClellan)
Re: Regular expression <rootbeer@teleport.com>
Re: Regular expression (Honza Pazdziora)
Reverse Engineer Time strings <godfrey@hnashe.com>
Re: Reverse Engineer Time strings (Jeremy D. Zawodny)
Re: socket to http (Greg Bacon)
Re: substituting special chars (Bart Lateur)
Re: substituting special chars (Tad McClellan)
Re: week-of-the-year calculation (Steffen Beyer)
XS (Toad)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Sep 1997 08:43:58 GMT
From: mick@io.com (Michele Beltrame)
Subject: printing variables...
Message-Id: <slrn62msn2.ej.mick@caladan.weird.net>
Hallo!
Suppose you've got a piece of code like:
print <<End_of_prt;
<body background="$hpathbkg.jpg">
End_of_prt
The variable to be substituted is $hpath, so that the final output whould be
(supposing $hpath='/skm/'):
<body background="/skm/bkg.jpg">
However, Perl inteprets the full $hpathbkg as a variable name. How can I
resolve this without having to use more than one print function? If I use
something like:
print <<End_of_prt;
<body background="$hpath\bkg.jpg">
End_of_prt
it (obviously) substitutes the \b with a backspace character.
Thanks in advance, Miky.
--
Michele Beltrame
Italpro - Power Web Services
mick@io.com
http://www.italpro.com/mb
------------------------------
Date: 26 Sep 1997 08:46:16 GMT
From: mick@io.com (Michele Beltrame)
Subject: printing variables...
Message-Id: <slrn62msr0.ej.mick@caladan.weird.net>
Hallo!
Suppose you've got a piece of code like:
print <<End_of_prt;
<body background="$hpathbkg.jpg">
End_of_prt
The variable to be substituted is $hpath, so that the final output whould be
(supposing $hpath='/skm/'):
<body background="/skm/bkg.jpg">
However, Perl inteprets the full $hpathbkg as a variable name. How can I
resolve this without having to use more than one print function? If I use
something like:
print <<End_of_prt;
<body background="$hpath\bkg.jpg">
End_of_prt
it (obviously) substitutes the \b with a backspace character.
Thanks in advance, Miky.
--
Michele Beltrame
Italpro - Power Web Services
mick@io.com
http://www.italpro.com/mb
------------------------------
Date: Fri, 26 Sep 1997 11:11:57 +0200
From: Eike Grote <eike.grote@theo.phy.uni-bayreuth.de>
Subject: Re: printing variables...
Message-Id: <342B7C5D.15FB@theo.phy.uni-bayreuth.de>
Hi,
Michele Beltrame wrote:
>
> Hallo!
>
> Suppose you've got a piece of code like:
>
> print <<End_of_prt;
> <body background="$hpathbkg.jpg">
> End_of_prt
Use this instead:
<body background="${hpath}bkg.jpg">
^ ^
Bye, Eike
--
======================================================================
Eike Grote, Theoretical Physics IV, University of Bayreuth, Germany
----------------------------------------------------------------------
e-mail -> eike.grote@theo.phy.uni-bayreuth.de
WWW -> http://www.phy.uni-bayreuth.de/theo/tp4/members/grote.html
http://www.phy.uni-bayreuth.de/~btpa25/
======================================================================
------------------------------
Date: Fri, 26 Sep 1997 05:52:03 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Annie P. Harding" <amhardin@erols.com>
Subject: Re: processing variable input variables
Message-Id: <Pine.GSO.3.96.970926054358.376H-100000@usertest.teleport.com>
On Thu, 25 Sep 1997, Annie P. Harding wrote:
> <form ACTION=\"/cgi-bin/addetail.pl\" METHOD=\"GET\">
Rather than use so many backslashes, you may want to use alternative
quoting methods like q## or qq//, as described in the perlop(1) manpage.
> foreach $jobads (@JOBADS) {
> #create the variable name for the checkbox
> $checked = join('', "checked",$counter);
There's nothing wrong with that line, but it's easier to write and
understand this one, IMHO.
$checked = "checked$counter";
> <input TYPE=checkbox NAME=$checked VALUE=$jobads[0]> JOB INFO
I think that this was supposed to be a string in double quotes, probably
intended to be printed.
> $in{'$checked'} should be picking up the value of "checked1", "checked2"
> etc....is there an easier way to process a variable number of
> checkboxes??
@names = keys %in; # Perhaps?
@checkbox_names = grep /^checked\d+$/, keys %in; # or this?
Of course, you should use CGI.pm in place of cgi-lib.pl. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Fri, 26 Sep 1997 13:45:19 +0100
From: Godfrey Smith <godfrey@hnashe.com>
Subject: Re: Question: How to generate same "random" numbers...
Message-Id: <342BAE5F.2816@hnashe.com>
Nevin Kapur wrote:
>
> Is it possible to generate repeatable sets of random numbers using perl.
> What I need is some function which will accept a seed and repeatedly
> generate the same random numbers.
>
> Thanks,
>
> Nevin
Hi Nev,
little script I knocked up to win the Lottery here in the UK
its a but scruffy but it works
It won me 10 pounds
feel free to modify it
Godfrey
#!/usr/local/bin/perl
#print "Initialising Random Numbers.............\n";
srand;
#print "Done\n";
#print "Initialising Array with blank entries.................\n";
@list = ("0","0", "0","0","0","0");
#print "Done\n";
$list =1;
$count = 0;
while ($count < 50) {
push (@lottnumbers, $list);
$count++;
$list++;
} # end while
#print "Here are the lottery Numbers in total...@lottnumbers\n";
$mark = 0;
#print "Now getting 6 numbers from list\n";
while ($mark < 6 ) {
$guess = rand (@lottnumbers);
@new = split(/\./, $guess);
$guess = $new[0];
# print "number to test = $guess \n";
if ($guess == $list[0]) {
# print"Matched at position 0 Discarding\n";
push (@trash ,$guess );
} else {
if ($guess == $list[1]) {
# print"Matched at position 1 Discarding\n";
push (@trash ,$guess );
} else {
if ($guess == $list[2]) {
# print"Matched at position 2 Discarding\n";
push (@trash ,$guess );
} else {
if ($guess == $list[3]) {
# print"Matched at position 3 Discarding\n";
push (@trash ,$guess );
} else {
if ($guess == $list[4]) {
# print"Matched at position 4 Discarding\n";
push (@trash ,$guess );
} else {
if ($guess == $list[5]) {
# print"Matched at position 5 Discarding\n";
push (@trash ,$guess );
} else {
shift (@list);
push (@list ,$guess );
$mark++;
}
}
}
}
}
}
}
#print "sorting numbers using spaceship operator\n";
@end = sort { $a <=> $b } @list;
print "Here are this weeks Lottery choices @end\n";
print "Numbers duplicated and discarded = @trash\n";
------------------------------
Date: Fri, 26 Sep 1997 11:12:37 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: Read AND WRITE dBASE files from Perl
Message-Id: <342B7C84.3E4D4475@absyss.fr>
David Grove wrote:
>
> Does anyone know of a module, or whatever, or any way whatsover, to
> read AND WRITE dBASE files from Perl. Xbase.pm won't write.
>
> I'm using Perl 5.004 on Windows 95 B.
This is the third time I've seen an XBASE question in the past 10 days.
Why has it become so popular? The answer is "no", there is no Xbase
module to write files. I started one, but never finished it (the .cdx
file is never updated) and I've given that to a number of people for
them to look into finishing it. I've asked them to post it to CPAN when
(if) they get it to work. If you need the names of people doing this,
you'll have to use DejaNews and search because I didn't keep any
records.
- doug
------------------------------
Date: Fri, 26 Sep 1997 14:07:04 +0200
From: Claus <claus@selle.com>
Subject: Regular expression
Message-Id: <342BA568.71C73904@selle.com>
I need to replace the following in a line
"http://193.21.123.21/test.html"
The ip number wil change but the front and end data will be the same,
but I can't make a expression that wil detect the data.
Example of line :
<IMG SRC="http://193.21.234.21/webcam.jpg" NOSAVE HEIGHT=240 WIDTH=320>
Claus
------------------------------
Date: Fri, 26 Sep 1997 08:03:00 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Regular expression
Message-Id: <4qbg06.dp.ln@localhost>
Claus (claus@selle.com) wrote:
: I need to replace the following in a line
: "http://193.21.123.21/test.html"
: The ip number wil change but the front and end data will be the same,
: but I can't make a expression that wil detect the data.
Where are the ones you tried?
If you post them, someone may show you where you went wrong, so
you won't end up doing it again the next time...
: Example of line :
: <IMG SRC="http://193.21.234.21/webcam.jpg" NOSAVE HEIGHT=240 WIDTH=320>
s/\Q193.21.123.21/193.21.234.21/g;
or
s/193\.21\.123\.21/193.21.234.21/g;
or, more safely:
s!\Qhttp://193.21.123.21!http://193.21.234.21!g;
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 26 Sep 1997 06:46:43 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Claus <claus@selle.com>
Subject: Re: Regular expression
Message-Id: <Pine.GSO.3.96.970926064404.376Q-100000@usertest.teleport.com>
On Fri, 26 Sep 1997, Claus wrote:
> Subject: Regular expression
Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
> I need to replace the following in a line
> "http://193.21.123.21/test.html"
> The ip number wil change but the front and end data will be the same,
> but I can't make a expression that wil detect the data.
> Example of line :
> <IMG SRC="http://193.21.234.21/webcam.jpg" NOSAVE HEIGHT=240 WIDTH=320>
Are you saying that you need to change just the numbers?
s#\b193\.21\.123\.21\b#123.45.67.8#g; # Like this, maybe?
If that's not it, please try asking again. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Fri, 26 Sep 1997 13:50:57 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Regular expression
Message-Id: <adelton.875281857@aisa.fi.muni.cz>
Claus <claus@selle.com> writes:
> I need to replace the following in a line
> "http://193.21.123.21/test.html"
> The ip number wil change but the front and end data will be the same,
> but I can't make a expression that wil detect the data.
>
> Example of line :
> <IMG SRC="http://193.21.234.21/webcam.jpg" NOSAVE HEIGHT=240 WIDTH=320>
s!193\.21\.234\.21!your.ip.address!g
could make the job. Or did not I catch what you wanted?
Hope this helps.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: Fri, 26 Sep 1997 12:42:44 +0100
From: Godfrey Smith <godfrey@hnashe.com>
Subject: Reverse Engineer Time strings
Message-Id: <342B9FB4.7220@hnashe.com>
I have to take a string and translate it into the
numerical time format. (since the epoch)
platform NT4.0
the strings look like this:
22/Sep/1997:12:23:26
if anyone can supply a line of code
I would be grateful
Godfrey Smith
------------------------------
Date: Fri, 26 Sep 1997 13:52:30 GMT
From: zawodny@hou.moc.com (Jeremy D. Zawodny)
Subject: Re: Reverse Engineer Time strings
Message-Id: <342bbdf2.153126734@igate.hst.moc.com>
[cc'd automagically to original author]
On Fri, 26 Sep 1997 12:42:44 +0100, Godfrey Smith <godfrey@hnashe.com>
wrote:
>I have to take a string and translate it into the
>numerical time format. (since the epoch)
>
>platform NT4.0
>
>the strings look like this:
>
>22/Sep/1997:12:23:26
>
>if anyone can supply a line of code
>I would be grateful
There *might* be a one-liner to do it, but I'd suggest using one of
the Date/Time modules available on CPAN.
Good Luck,
Jeremy
--
Jeremy Zawodny
Internet Technology Group
Information Technology Services
Marathon Oil Company, Findlay Ohio
http://www.marathon.com/
Unless explicitly stated, these are my opinions only--not those of my employer.
------------------------------
Date: 26 Sep 1997 13:34:56 GMT
From: gbacon@adtran.com (Greg Bacon)
To: ben@reser.org (Ben Reser)
Subject: Re: socket to http
Message-Id: <60gdm0$fs6$1@info.uah.edu>
[Posted and mailed]
In article <342b28b8.31513273@192.168.0.1>,
ben@reser.org (Ben Reser) writes:
: Save your self some trouble and use LIBWWW-Perl.
: You can find it on CPAN at:
: http://language.perl.com/cgi-bin/cpan_mod?module=LWP
Since we're talking about saving trouble, why not
% perl -MLWP::Simple -e 'getprint shift' URL
Hope this helps,
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Fri, 26 Sep 1997 09:24:26 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: substituting special chars
Message-Id: <342f7b19.5145648@news.tornado.be>
Per Fredrik Kvarme <perkva@itk.ntnu.no> wrote:
>... Part of that means I have to substitute all the MS-DOS "\"
>chars with the UNIX "/". I've tried $string =~ s/\\/\//g and lots of other
>ways to do so, but that doesn't make for any change at all in a teststing
>like e.g. "c:\user\files\", etc.
The problem is not in your substitution, but in your test string.
Try this:
print "c:\user\files\"
and
print 'c:\\user\\files\\";
The second case will show the string you want. Morale: always double
backslashes in literal strings, even between single quotes.
HTH,
Bart.
------------------------------
Date: Fri, 26 Sep 1997 08:06:49 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: substituting special chars
Message-Id: <91cg06.dp.ln@localhost>
Bart Lateur (bart.mediamind@tornado.be) wrote:
: Per Fredrik Kvarme <perkva@itk.ntnu.no> wrote:
: >... Part of that means I have to substitute all the MS-DOS "\"
: >chars with the UNIX "/". I've tried $string =~ s/\\/\//g and lots of other
: >ways to do so, but that doesn't make for any change at all in a teststing
: >like e.g. "c:\user\files\", etc.
: The problem is not in your substitution, but in your test string.
: Try this:
: print "c:\user\files\"
: and
: print 'c:\\user\\files\\";
: The second case will show the string you want. Morale: always double
: backslashes in literal strings, even between single quotes.
Moral: always double backslashes in literal strings, even between
single quotes, else your morale may suffer.
;-)
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: 26 Sep 1997 10:50:55 GMT
From: sb@en.muc.de (Steffen Beyer)
Subject: Re: week-of-the-year calculation
Message-Id: <60g42f$6m1$2@en1.engelschall.com>
Fridiric GILLES <gilles@tls-cats.sps.mot.com> wrote:
> In Perl FAQ related to dates:
> > use Time::localtime;
> > $day_of_year = localtime(time())->yday;
> >
> > You can find the week of the year by dividing this by 7:
> >
> > $week_of_year = int($day_of_year / 7);
> >
> > Of course, this believes that weeks start at zero.
> >
> The week-of-the-year calculation is not true because the week is not
> supposed to begin with a Monday!
> Here is the right calculation:
> ($wday,$yday)=(localtime)[6,7];
> $wday=7 if $wday==0; # to make Sunday the last day of the week
> $week=int(($yday-$wday)/7 + 2);
> Frederic GILLES
This is not compliant with the relevant norms in vigor!
Week number calculations according to ISO/R 2015-1971 and DIN 1355 standards
are included in the module "Date::DateCalc", which is available from any
CPAN ftp site, i.e.:
http://www.perl.com/CPAN/modules/by-module/DateCalc-3.2.tar.gz
or from my web site at
http://www.engelschall.com/u/sb/download/
where you can also find more details about these norms (if you understand
a text in german).
Best regards,
--
Steffen Beyer <sb@sdm.de> http://www.engelschall.com/u/sb/
"There is enough for the need of everyone in this world,
but not for the greed of everyone." - Mahatma Gandhi
>> Unsolicited commercial email goes directly to /dev/null <<
------------------------------
Date: Fri, 26 Sep 1997 13:09:22 +0200
From: toad@hem1.passagen.se (Toad)
Subject: XS
Message-Id: <MPG.e95b64ffb4f1370989682@nntpserver.swip.net>
I need to create a Perl interface to a .so file that I've created in C.
As I understand it you're supposed to use XS, rigth? And I've looked
through the xstut man page, but frankly I think I need some more
comprehensible info on this subject. I did the steps described, but it
didn't do it for me :(
Any help appriciated!
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 1084
**************************************