[11465] in Perl-Users-Digest
Perl-Users Digest, Issue: 5065 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 5 12:07:23 1999
Date: Fri, 5 Mar 99 09:00:21 -0800
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, 5 Mar 1999 Volume: 8 Number: 5065
Today's topics:
Re: $1 gets clobbered (Tad McClellan)
Re: $1 gets clobbered (Abigail)
Re: Beginning Perl Programmer (Tad McClellan)
Centering a submit button using CGI.pm. Possible? (James W. Sandoz)
COnverting comma separate values beardy4238@my-dejanews.com
Re: COnverting comma separate values (Clay Irving)
Re: COnverting comma separate values <"rhrh@hotmail.com,or,rhardicr"@ford.com>
Re: COnverting comma separate values (Jonathan Stowe)
Re: deletion problem (Jonathan Stowe)
Re: deletion problem (Larry Rosler)
Expand a specific number (Claes Bjorklund)
Re: Expand a specific number <Allan@due.net>
Re: Expand a specific number <Allan@due.net>
FAQ 1.8: How does Perl compare with other languages lik <perlfaq-suggestions@perl.com>
Re: Help: How to pass thru apostrophe (Tad McClellan)
Re: IO::File problem (M.J.T. Guy)
need to connect and translate domain number to name gemhound@gemhound.com
Re: need to connect and translate domain number to name <Tony.Curtis+usenet@vcpc.univie.ac.at>
Printing in Perl dennishancy@eaton.com
Re: Printing in Perl (Jonathan Stowe)
Re: Printing to multiple Filehandles simultaneously (Andrew M. Langmead)
Programming a package sub that takes a reference to a v <michael.preminger@jbi.hioslo.no>
Re: q// vs. '' (Tad McClellan)
RealAudio Dynamic CGI RAM MetaFiles Question skotos@my-dejanews.com
Seriously confused about subscripts <jcwren@atlanta.com>
Re: Statistics on what people search for.. (Roger Foss)
system()/print question (Jake)
Re: system()/print question <Tony.Curtis+usenet@vcpc.univie.ac.at>
Re: warning: unquoted string...... <nils@hotmail.com>
Re: y2k and 4-digit dates (was Re: foreach and while) <staffan@ngb.se>
Re: Yesterday! (Benjamin Franz)
Re: Yesterday! (Larry Rosler)
Re: Yesterday! <dgris@moiraine.dimensional.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 5 Mar 1999 04:30:13 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: $1 gets clobbered
Message-Id: <578ob7.trn.ln@magna.metronet.com>
Jim and Paula (gemhound@gemhound.com) wrote:
: Can someone please explain to me why $1 is getting clobbered in the
: last line below?
The standard perl docs can explain that (perlre.pod)
"The scope of $E<lt>digitE<gt> (and C<$`>, C<$&>, and C<$'>)
extends to the end of the enclosing BLOCK or eval string,
or to the next successful pattern match, whichever comes first."
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: It becomes uninitialized and I get an undefined warning when I try to
: print it even though I'm not using pattern memory.
Using or not using pattern memory does not matter.
Successful/unsuccessful matching is what matters.
: I thought you
: could use $# just like any other variable as long as you didn't fill
: it up again with pattern memory or go out of the block.
: use diagnostics;
: $string = "this is not good";
: $string =~ /(not)/;
: print $1 , "\n"; # prints "not"
: if ($1 =~ /not/){ print "Say what?";}
^^^^
^^^^ successful match, capturing vars are undef'd
: print $1 , "\n";
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 5 Mar 1999 16:31:30 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: $1 gets clobbered
Message-Id: <7bp0t2$t5$1@client2.news.psi.net>
Jim and Paula (gemhound@gemhound.com) wrote on MMXII September MCMXCIII
in <URL:news:36df7b2e.3308952@news.primeline.com>:
%% Can someone please explain to me why $1 is getting clobbered in the
%% last line below?
%%
%% It becomes uninitialized and I get an undefined warning when I try to
%% print it even though I'm not using pattern memory. I thought you
%% could use $# just like any other variable as long as you didn't fill
%% it up again with pattern memory or go out of the block.
%%
%% use diagnostics;
%%
%% $string = "this is not good";
%%
%% $string =~ /(not)/;
%%
%% print $1 , "\n"; # prints "not"
%%
%% if ($1 =~ /not/){ print "Say what?";}
%%
%% print $1 , "\n";
It works for me. Don't you get the 'Use of uninitialized value' warning?
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
------------------------------
Date: Fri, 5 Mar 1999 03:45:04 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Beginning Perl Programmer
Message-Id: <gi5ob7.fjn.ln@magna.metronet.com>
Matt Fenning (mfenning@voicenet.com) wrote:
: Can i install and develop in Perl on Windows 95,98 or WinNT?
Yep.
: If so where can I get the source code?
Perl FAQ, part 2:
------------------------------------------------
=head2 What machines support Perl? Where do I get it?
The standard release of Perl (the one maintained by the perl
development team) is distributed only in source code form. You
can find this at http://www.perl.com/CPAN/src/latest.tar.gz, which
in standard Internet format (a gzipped archive in POSIX tar format).
Perl builds and runs on a bewildering number of platforms. Virtually
all known and current Unix derivatives are supported (Perl's native
platform), as are proprietary systems like VMS, DOS, OS/2, Windows,
QNX, BeOS, and the Amiga. There are also the beginnings of support
for MPE/iX.
Binary distributions for some proprietary platforms, including
Apple systems can be found http://www.perl.com/CPAN/ports/ directory.
Because these are not part of the standard distribution, they may
and in fact do differ from the base Perl port in a variety of ways.
You'll have to check their respective release notes to see just
what the differences are. These differences can be either positive
(e.g. extensions for the features of the particular platform that
are not supported in the source release of perl) or negative (e.g.
might be based upon a less current source release of perl).
A useful FAQ for Win32 Perl users is
http://www.endcontsw.com/people/evangelo/Perl_for_Win32_FAQ.html
------------------------------------------------
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 5 Mar 1999 10:57:49 -0500
From: sandoz@umbc.edu (James W. Sandoz)
Subject: Centering a submit button using CGI.pm. Possible?
Message-Id: <7boutt$128hk@umbc7.umbc.edu>
Greetings!
I've been trying to place the submit (and reset) button on the center
of the line, using CGI.pm. I've read Lincoln Stein's Official Guide
as well as the on-line documentation at wiley.com to no avail. I've
also tried a few tricks such as
submit({align=>'center'}-name=>'Set'),
center(reset(-name =>'Reset')),
The buttons work just fine, but placing them where I want has been
more difficult than I'd thought. I _could_ write the form code in
plain 'ol html and then process it with CGI.pm, but that seems a
waste of a good tool.
If someone could point me to the correct documentation (or to what I've
perhaps overlooked) I'd be most appreciative.
Jim Sandoz
--
Mr. James W. Sandoz, Instructor, UMBC Dept of Biol Sciences,
1000 Hilltop Circle
Catonsville, MD 21250
voice: (410) 455-3497; fax: 455-3875; net: sandoz@umbc.edu
------------------------------
Date: Fri, 05 Mar 1999 14:32:04 GMT
From: beardy4238@my-dejanews.com
Subject: COnverting comma separate values
Message-Id: <7bopt3$mlj$1@nnrp1.dejanews.com>
I am reading in a list of values like
36,37,38
into a perl script $tring.
I want to be able to reference them via a @array like
36
37
38
How do I convert between the input CSV and the output newline array?
:-)
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 5 Mar 1999 10:06:26 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: COnverting comma separate values
Message-Id: <slrn7dvsnh.q1s.clay@panix.com>
On Fri, 05 Mar 1999 14:32:04 GMT, beardy4238@my-dejanews.com
<beardy4238@my-dejanews.com> wrote:
>I am reading in a list of values like
> 36,37,38
>into a perl script $tring.
>
>I want to be able to reference them via a @array like
> 36
> 37
> 38
>
>How do I convert between the input CSV and the output newline array?
If its as simple as you describe, use split:
#!/usr/local/bin/perl5 -w
$list = "36,37,38";
@array = split /,/, $list;
foreach $element (@array) {
print "$element\n";
}
This program prints:
36
37
38
--
Clay Irving <clay@panix.com>
BREAKFAST.COM Halted... Cereal Port Not Responding.
------------------------------
Date: Fri, 05 Mar 1999 14:55:44 +0000
From: Richard H <"rhrh@hotmail.com,or,rhardicr"@ford.com>
Subject: Re: COnverting comma separate values
Message-Id: <7bor88$k7t5@eccws1.dearborn.ford.com>
beardy4238@my-dejanews.com wrote:
>
> I am reading in a list of values like
> 36,37,38
> into a perl script $tring.
>
> I want to be able to reference them via a @array like
> 36
> 37
> 38
use the split function with comma as your delimiter
Richard H
------------------------------
Date: Fri, 05 Mar 1999 15:33:42 GMT
From: gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: COnverting comma separate values
Message-Id: <36dff7aa.23706412@news.dircon.co.uk>
On Fri, 05 Mar 1999 14:32:04 GMT, beardy4238@my-dejanews.com wrote:
>I am reading in a list of values like
> 36,37,38
>into a perl script $tring.
>
>I want to be able to reference them via a @array like
> 36
> 37
> 38
>
>How do I convert between the input CSV and the output newline array?
>
Oh puleeze ...
This is pretty fundamental stuff. I think what is confusing you is
that you are thinking of it as conversion rather than as division into
smaller parts - there is a five letter word beginning with S that one
uses for this and by some strange coincidence this also the name of a
function that will achieve this in Perl.
Of course I am certain that you will feel hard done by at this
response but a world of knowledge awaits you if you type:
perl -v
and follow the advice in the last paragraph that is displayed.
/J\
------------------------------
Date: Fri, 05 Mar 1999 14:22:57 GMT
From: gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: deletion problem
Message-Id: <36dfe80d.19708712@news.dircon.co.uk>
On Fri, 05 Mar 1999 12:57:11 +0000, anthony belsey <anb5@aber.ac.uk>
wrote:
>can any one help?
>
>I have a text file with data in.
>
>My program reads that file and searches for a key word.
>If that key word is found, then that line is deleted from the
>file.
>
I cant actually remember Tom's program posting this one but the answer
to this question is best found in perlfaq5:
=head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq5.pod
=head2 How do I change one line in a file/delete a line in a
file/insert a line in the middle of a file/append to the beginning of
a file?
The executive sumary of which is that you need to use a temporary
file.
/J\
------------------------------
Date: Fri, 5 Mar 1999 07:47:27 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: deletion problem
Message-Id: <MPG.11499c671f4dd3cc9896e8@nntp.hpl.hp.com>
In article <36DFD30A.EAFF58EF@aber.ac.uk> on Fri, 05 Mar 1999 12:50:18
+0000, anthony belsey <anb5@aber.ac.uk >says...
> Can any one help?
>
> I have a text file with data in.
>
> my program accesses this file and searches for a key to a line.
> if the search is successfull, I then want to delete that line off the
> text file.
>
> every thing I do fails to delete that line.
I don't know which of your seven (7!) submissions to respond to to tell
you that this is a FAQ. perlfaq5: "How do I change one line in a
file/delete a line in a file/insert a line in the middle of a
file/append to the beginning of a file?"
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 5 Mar 1999 13:57:44 GMT
From: claes@canit.se (Claes Bjorklund)
Subject: Expand a specific number
Message-Id: <claes-0503991512300001@p52.one.canit.se>
Hi
Have tried to solve this by my self but I can't
have to find and a specific number from a string and then get it
the problem is that the number contain comma and the string must
have word with a colon (:) at the end
Have read the chapter regular expression in the book Programming Perl
but can't find a good solution
This script works but its ugly
#!perl
$s='<b>Population:</b> 4,419,955.6 (July 1998 est.) ';
@pop=($s =~ /(\w*:)/g);
print $pop[0];
print "\n";
if ($s=~/$pop[0]/){
@b=($s=~m/(\d+\.?\d*|\.\d+)/g);
$num=join('',@b[0..$#b-1]);
print @b;
print "\n";
print $num;
push(@data,$pop[0].$num);
}
print "\n";
#@c=($s=~m/>(\w+)/g);
print @data;
print "\n";
Can someone help me, please?
\Claes
------------------------------
Date: Fri, 5 Mar 1999 10:47:47 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Expand a specific number
Message-Id: <7botuj$bah$1@samsara0.mindspring.com>
Claes Bjorklund wrote in message ...
:Hi
:Have tried to solve this by my self but I can't
:have to find and a specific number from a string and then get it
:the problem is that the number contain comma and the string must
:have word with a colon (:) at the end
:Have read the chapter regular expression in the book Programming Perl
:but can't find a good solution
:
:This script works but its ugly
:
:#!perl
:$s='<b>Population:</b> 4,419,955.6 (July 1998 est.) ';
:@pop=($s =~ /(\w*:)/g);
:print $pop[0];
:print "\n";
:
:if ($s=~/$pop[0]/){
: @b=($s=~m/(\d+\.?\d*|\.\d+)/g);
: $num=join('',@b[0..$#b-1]);
: print @b;
: print "\n";
: print $num;
: push(@data,$pop[0].$num);
:}
:print "\n";
:
:#@c=($s=~m/>(\w+)/g);
:print @data;
:print "\n";
:Can someone help me, please?
Yikes, there certainly is more than one way to do it <g>. Kudos for
perseverance. If I assume you always want the first number which might
contain commas (123,456.89 or 123 or .6 ) after some number of \w ending
with :, how about:
#!/usr/local/bin/perl -w
use strict;
my $s='<b>Population: </b> 1,233,213.234 (July 1998 est.) ';
my ($word, $num) = $s=~m/(\w+:).*?(.?[\d,]+\.?[\d,]*)/;
$num =~ tr/,//d;
print "$word $num\n";
If you really only want the : you can go back to \w*. This will match
1,2,3,4,5.5,6 but if that is a problem you can move on from here.
HTH
AmD
--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
Hey, I had to let awk be better at *something*... :-)
- Larry Wall in <1991Nov7.200504.25280@netlabs.com>1
------------------------------
Date: Fri, 5 Mar 1999 11:27:49 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Expand a specific number
Message-Id: <7bp09m$d6b$1@samsara0.mindspring.com>
Allan M. Due wrote in message <7botuj$bah$1@samsara0.mindspring.com>...
:Claes Bjorklund wrote in message ...
::Hi
::
[snip]
::Can someone help me, please?
:
:
:Yikes, there certainly is more than one way to do it <g>. Kudos for
:perseverance. If I assume you always want the first number which might
:contain commas (123,456.89 or 123 or .6 ) after some number of \w ending
:with :, how about:
:
:#!/usr/local/bin/perl -w
:use strict;
:
:my $s='<b>Population: </b> 1,233,213.234 (July 1998 est.) ';
:my ($word, $num) = $s=~m/(\w+:).*?(.?[\d,]+\.?[\d,]*)/;
How did that extra , get in there.
my ($word, $num) = $s=~m/(\w*:).*?(.?[\d,]+\.?\d*)/;
$num =~ tr/,//d;
print "$word $num\n";
AmD
--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
echo "ICK, NOTHING WORKED!!! You may have to diddle the includes.";
- Larry Wall in Configure from the perl distribution
------------------------------
Date: 5 Mar 1999 09:10:05 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 1.8: How does Perl compare with other languages like Java, Python, REXX, Scheme, or Tcl?
Message-Id: <36e001dd@csnews>
(This excerpt from perlfaq1 - General Questions About Perl
($Revision: 1.21 $, $Date: 1999/01/26 09:55:05 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq1.html
if your negligent system adminstrator has been remiss in his duties.)
How does Perl compare with other languages like Java, Python, REXX, Scheme, or Tcl?
Favorably in some areas, unfavorably in others. Precisely which
areas are good and bad is often a personal choice, so asking this
question on Usenet runs a strong risk of starting an unproductive
Holy War.
Probably the best thing to do is try to write equivalent code to
do a set of tasks. These languages have their own newsgroups in
which you can learn about (but hopefully not argue about) them.
Some comparison documents can be found at
http://language.perl.com/versus/ if you really can't stop
yourself.
--
"Make is like Pascal: everybody likes it, so they go in and change it. "
--Dennis Ritchie
------------------------------
Date: Fri, 5 Mar 1999 03:42:57 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Help: How to pass thru apostrophe
Message-Id: <he5ob7.fjn.ln@magna.metronet.com>
Dean Enix (denix@cfer.com) wrote:
: The following perl statement works okay
: `/usr/bin/cut -d'|' -f1,3- $results \> filtered.out`;
: but when I try to change the delimiter to ' (apostrophe) it doesn't get
: passed thru...
It is not supposed to get passed through with single quotes.
If you want it passed through, then backwards single quotes
are what you want, though I nearly always use the alternative
syntax:
qx!/usr/bin/cut -d'|' -f1,3- $results \> filtered.out!;
But I _never ever_ do that either, because that code doesn't
_do_ anything with the output of the command (and, since
you have redirected the output anyway, system() should
be used here instead of qx//).
Escaping the angle bracket is not necesary either.
system qq(/usr/bin/cut -d'|' -f1,3- $results > filtered.out) &&
die "problem running system() command $!";
: What are the rules here?
The semantics associated with a particular syntax are well defined,
but where those are the semantics that you _want_ kinda depends
on what you want to do, which you have not shared with us.
(do you want to capture the output in your Perl, or do you just
want to create a file with the output in it?
)
: Any suggestions on a solution?
If we knew what you wanted, we could make suggestions...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 5 Mar 1999 16:34:48 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: IO::File problem
Message-Id: <7bp138$686$1@pegasus.csx.cam.ac.uk>
Klaus Johannes Rusch <KlausRusch@atmedia.net> wrote:
>
>The following code core dumps under Perl 5.003_93 for OS/2:
^^^^^^^^
That's a very old development release of Perl, quite unsupported.
>use IO::File;
>$fh = IO::File -> new_tmpfile() or die "$!";
>print $fh "Test";
>$fh -> setpos(1);
>
>Process terminated by SIGSEGV
>
>
>Bug or error in my code?
A SEGV from a supported release of Perl is always a bug, even if it's
provoked by a user error.
So if you get the same effect with a current Perl release, please let us
know. Use the perlbug script to send the report.
Mike Guy
------------------------------
Date: Fri, 05 Mar 1999 16:32:54 GMT
From: gemhound@gemhound.com
Subject: need to connect and translate domain number to name
Message-Id: <7bp0vm$t8c$1@nnrp1.dejanews.com>
I'm trying to learn internet sockets and having no luck at all. Could
someone just post or send a small Working example of connecting and getting a
domain Name from a Number i.e. translate 12.18.59.111 to somebody.com.
That's all I need to do for a server log analysis program I'm working on. Or
tell me where a script is that does that. If I can get one thing working that
I can put in a useful program, I think I can go on from there. I need a full
working example since I've tried everything (yes, I was logged on ;') But
where the book says gethostbyaddress looks up a domain name server, I'm not
even sure what that refers to -- any working domain name like my website at
gemhound.com or is that something special? I'm studying this stuff, but I
need to do some things with my logs now, since who is visiting is important
for various reasons.
I'm using ActiveState Win32 Perl, which may be one problem, at least as
regards reference material, since out of the five Perl books I have, the only
one with explicit detail on sockets that actually tells you what all the
variables are for is not Win32 oriented. Also, the title of a good book on
this would be appreciated, although I just blew well over a hundred bucks on
those five, so I'll wait a bit on that ;') Boy, these computer books are
high.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 05 Mar 1999 17:46:50 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: need to connect and translate domain number to name
Message-Id: <83k8wv6g05.fsf@vcpc.univie.ac.at>
Re: need to connect and translate domain number to
name, gemhound <gemhound@gemhound.com> said:
gemhound> I'm trying to learn internet sockets and
gemhound> having no luck at all. Could someone just
there's no direct connection (pun not intended :-)
between address lookup and sockets.
gemhound> post or send a small Working example of
gemhound> connecting and getting a domain Name from
gemhound> a Number i.e. translate 12.18.59.111 to
gemhound> somebody.com. That's all I need to do for
gemhound> a server log analysis program I'm working
Do you know about analog?
http://www.statslab.cam.ac.uk/~sret1/analog/
gemhound> on. Or tell me where a script is that
gemhound> does that. If I can get one thing working
Something like this from the ground up, or check
CPAN for Net:: modules
my $ip = '192.48.96.9';
my $packed = pack('C4', split(/\./, $ip));
use Socket;
my ($name,$aliases,$addrtype,$length,@addrs) =
gethostbyaddr($packed, AF_INET);
print "$name\n" if defined $name;
gemhound> up a domain name server, I'm not even sure
gemhound> what that refers to -- any working domain
gemhound> name like my website at gemhound.com or is
gemhound> that something special? I'm studying this
Depends on how name resolution on your machine is
set up. Presumably this information will have been
supplied to you by your ISP or local network admin.
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien. | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds! | private email:
Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>
------------------------------
Date: Fri, 05 Mar 1999 14:42:39 GMT
From: dennishancy@eaton.com
Subject: Printing in Perl
Message-Id: <7boqgs$n89$1@nnrp1.dejanews.com>
I'm hoping this question has a simple answer.
In Perl, I need to print a series of HTML form values to a text file. I
understand how to retrieve these values; but how can I produce formatted
output?
In other other words, field #1 is a text value of four characters that will
be printed in positions 1-4; field #2 is numeric and will be printed in
positions 5-12 in the format #####.##; and so on.
Any advice would be appreciated. Thanks!
Dennis Hancy
Eaton Corporation
Cleveland, OH
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 05 Mar 1999 15:25:46 GMT
From: gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Printing in Perl
Message-Id: <36dff635.23333454@news.dircon.co.uk>
On Fri, 05 Mar 1999 14:42:39 GMT, dennishancy@eaton.com wrote:
>I'm hoping this question has a simple answer.
>
>In Perl, I need to print a series of HTML form values to a text file. I
>understand how to retrieve these values; but how can I produce formatted
>output?
>
>In other other words, field #1 is a text value of four characters that will
>be printed in positions 1-4; field #2 is numeric and will be printed in
>positions 5-12 in the format #####.##; and so on.
>
You will want to use the builtin function(s) (s)printf ...
=item sprintf FORMAT, LIST
Returns a string formatted by the usual C<printf()> conventions of the
C library function C<sprintf()>. See L<sprintf(3)> or L<printf(3)>
on your system for an explanation of the general principles.
..
=cut
Of course if you are not on a Unix system or have never used C then
you might not have known about that but nonetheless it is in the
documentation which should be available whatever platform you are on.
/J\
------------------------------
Date: Fri, 5 Mar 1999 15:23:37 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Printing to multiple Filehandles simultaneously
Message-Id: <F84o3D.JD5@world.std.com>
Gavin Sherlock <sherlock@genome.stanford.edu> writes:
>for ($i=0; $i<100; $i++){
> print {$file[$i]} "Stuff to print";
>}
>but is there a way of omitting the for loop, like:
You could hide the loop in a module that implements perl's tied
filehandle interface:
tie *ALL, MultiHandle, *STDOUT, *STDOUT or die;
print *ALL "Stuff to print";
with an implementation of MultiHandle that would look like this:
package MultiHandle;
sub TIEHANDLE {
my ($class, @files) = @_;
bless [ @files ], $class;
}
sub PRINT {
my ($self, @args) = @_;
for my $handle (@$self) {
print $handle @args;
}
}
I thought there was a CPAN module that did this, but I can't find it
now.
--
Andrew Langmead
------------------------------
Date: Fri, 05 Mar 1999 15:01:28 +0000
From: Michael Preminger <michael.preminger@jbi.hioslo.no>
Subject: Programming a package sub that takes a reference to a variable.
Message-Id: <36DFF1C8.AF091E7@jbi.hioslo.no>
Within a package, I am trying to do the following
sub updateEntryNoTree(%$*){
my(%Entry,$dbh,*index)=@_;
code.....
}
so as to keep the value of $index across calls and returns.
The perl interpreter says
Variable "$index" is not imported at Bb_pack.pm line 264.
What am I doing wrong?
Thanks!
Michael
--
Michael Preminger
Forsker / Research Scientist
Avdeling for journalistikk,
bibliotek- og informasjonsfag /
Faculty of Journalism, Library and
Information Science
Hxgskolen i Oslo / Oslo College
http://www.hioslo.no/~michaelp
Pilestredet 52, N-0167 Oslo
Voice: +47-22452778
Fax: +47-22452605
E-mail: michael.preminger@jbi.hioslo.no
------------------------------
Date: Fri, 5 Mar 1999 03:34:24 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: q// vs. ''
Message-Id: <gu4ob7.fjn.ln@magna.metronet.com>
Michael Balenger (MBalenger@worldnet.att.net) wrote:
: My vote for qw() instead of ""
: I use qw a lot to prevent me from having to put double quotes around my
^^^^^^^^^^^^^
: words and commas between them.
You should be using single quotes for those, unless they are
variables that you want interpolated, or if they contain
backslash escapes.
You should not ask for variable/backslash escape interpolation
unless you _need_ it. (when you use double quotes, you are
asking for those things)
Kind of a moot point, since you use qw() instead anyway...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 05 Mar 1999 15:04:58 GMT
From: skotos@my-dejanews.com
Subject: RealAudio Dynamic CGI RAM MetaFiles Question
Message-Id: <7borqi$ocn$1@nnrp1.dejanews.com>
I am interested in serving segments of our RealAudio files from a searchable
database. This will allow the user the ability to search the contents of our
audio shows (as entered into the database by hand) and then play only the
portion of the RealAudio file that is of interest.
What we need is a dynamic method to redirect the user to the RealAudio (.ra)
file with the appropriate start and stop times without the need for using a
static metafile (.ram) for every permutation.
I know that this has been done before; I found a Frontier script from a
programmer in Hawaii that would do it. I'd rather use PERL, if someone has a
couple of wise words to head me in the right direction.
Thanks in advance,
Trent
+---------------------------------------------+
J. Trent Adams trent@binarypro.com
New England Patriots 617.305.7829
New Media Producer
http://www.cybersideline.com
+---------------------------------------------+
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 05 Mar 1999 16:35:55 GMT
From: John "Chris" Wren <jcwren@atlanta.com>
Subject: Seriously confused about subscripts
Message-Id: <7bp15a$tcr$1@nnrp1.dejanews.com>
OK, I've been writing software for 20 years, and I like to think I know what
the heck I'm doing.
I'm trying to write a perl script, and I want to do something oh-so-trivial.
I have an array. The array is a result of HTML parsing, and contains the
following data. It is the result of using the HTML::LinkExtor->links
function, so the space between each words indicates an array element
a href doc_aa.htm
a href doc_ab.htm
...
a href doc_zz.htm
If I perform the loop "for (@docs) { print "$_->[2]\n"; }" I get what I
expect, each line displaying just the "doc_XX.htm" entry. I now want to
create a hashed table, with the index being the ?? portion of the file name
(?? being the two lettes after the underscore).
I know that { my $doc_indexs; $doc_indexes{$_->[2]} = $_->[2]; } will create
an entry in the hash table with the complete file name, and set the "data"
portion of the array (I forget the correct name just now) to "doc_??.htm".
However, what I really want is to set the index to just the ?? portion of the
file name. For all my reading, I can't seem to find the BASIC equivalent of
left$, right$, or mid$ (please, don't flame me about BASIC. It's just an
example of the functionality I want).
And I'm under the impression that using s/// requires that the data you want
to substitute to be in $/.
Am I being too 'C'-centric and missing the obvious? I know how to do this in
everything from 6502 assembly to PL/1, but I can't seem to make it happen in
perl...
-- John
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 5 Mar 1999 16:53:43 +0100
From: roger.foss@telenor.com (Roger Foss)
Subject: Re: Statistics on what people search for..
Message-Id: <MPG.114a1c72d44696c59896e1@134.47.108.15>
In article <7b4848$d4g$1@nnrp1.dejanews.com>,
droby@copyright.com says...
> In article <oeeyalmjwxt.fsf@alpha.hut.fi>,
> Jarkko Hietaniemi <jhi@alpha.hut.fi> wrote:
> >
> > roger.foss@telenor.com (Roger Foss) writes:
> > > I found www.searchwords.com, which lists the top 100 terms
> > > that people search for. It doesn't reveal its sources,
> > > though.
> > >
> > > And I want to know what people -in my company- search for.
> >
> > Why?
> >
>
> Big Brother, presumably. I can't imagine any other reason.
>
> I suppose you could do this by forcing them through a proxy that logs
> everything and writing a VERY intelligent analysis program, but it's a real
> expensive solution to a non-problem.
I'm sorry, but that is way too presumptuous.
Actually it is illegal in my country to monitor employees
e-mail, who they make phone calls to or their surfing
habits. But that's ok, there are log-anonymizing scripts.
At any rate, at our company we are using URL blocking
filters that block porn, hate and webpages with illegal
content.
The reason for using filters is mainly saving bandwidth,
but of course there's an interest in limiting time wasted
on surfing to sites that are irrelevant for work.
There have been a few reactions to the filters, but
nothing serious. It would be nice to actually -know-
how often people search for 'nude' or similar terms,
though.
A perl script that counts search terms wouldn't have
to be VERY intelligent. Its just a little beyond MY
perl skills.
I was imagining a script that would read through the
log files looking for URLs that contain Altavista, Yahoo
and other well known search engines. Then simply picking
out the relevant words after the ?q= part of the URLs.
Such a script would have to know a little bit about
query syntax of those search engines, but I'm guessing
it wouldn't be too hard for someone with more perl
skills than I have.
Thanks for the help.
Roger
------------------------------
Date: 5 Mar 1999 11:43:24 -0500
From: jacobc@emily.oit.umass.edu (Jake)
Subject: system()/print question
Message-Id: <36e009ac.0@oit.umass.edu>
I'm trying to print a text string to a file, output the results of
the system() call to the same file, then print another text string to the
file.
Example:
#!/usr/local/bin/perl
$OUTFILE = "test";
open(OUT,">>$OUTFILE");
print OUT "---- Beginning of Today's date ----\n";
system("/usr/bin/date >>$OUTFILE");
print OUT "---- End of Today's date ----\n";
close (OUT);
The results end up looking like this:
Fri Mar 5 11:23:23 EST 1999
---- Beginning of Today's date ----
---- End of Today's date ----
How can I get it to look like this:
---- Beginning of Today's date ----
Fri Mar 5 11:23:23 EST 1999
---- End of Today's date ----
Note*: In my actual script I'm not actually trying to get today's date. I'm
just using this script as an example to illustrate the behaviour I'm getting
when trying to use print statements and system().
Any advise would be greatly appreciated!
-Jake
------------------------------
Date: 05 Mar 1999 17:49:24 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: system()/print question
Message-Id: <83iucf6fvu.fsf@vcpc.univie.ac.at>
Re: system()/print question, Jake
<jacobc@emily.oit.umass.edu> said:
Jake> I'm trying to print a text string to a file,
Jake> output the results of the system() call to the
Jake> same file, then print another text string to
Jake> the file.
Jake> Example: #!/usr/local/bin/perl $OUTFILE =
Jake> "test"; open(OUT,">>$OUTFILE"); print OUT
Bzzt! Unchecked open() status.
Jake> "---- Beginning of Today's date ----\n";
Jake> system("/usr/bin/date >>$OUTFILE"); print OUT
Jake> "---- End of Today's date ----\n"; close
Jake> (OUT);
You're not autoflushing STDOUT, perldoc IO::Handle.
You need to make sure the 2 processes output
immediately.
But why use an external process when perl can do it
already?
perldoc -f localtime
perldoc POSIX (strftime).
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien. | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds! | private email:
Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>
------------------------------
Date: Fri, 5 Mar 1999 15:15:37 +0100
From: "Fredrik Larsson" <nils@hotmail.com>
Subject: Re: warning: unquoted string......
Message-Id: <NGRD2.766$EA1.1613@nntpserver.swip.net>
try this:
open (offenedatei, "<$tempdatei");
@formulardaten=<offenedatei>; #must use the @ instead of the $ because it
is an array
close (offenedatei);
/Larzon
>Hi there,
>
>I want to open a file and put the content of the file (html-file) into the
>array $formulardaten which will be
>changed by another part of the script.
>
>for opening and reading out the file I use the following code:
>
>open (offenedatei, "<$tempdatei");
>$formulardaten=<offenedatei>;
>close (offenedatei);
>
>when running the script with -w
>I always get the following warning:
>
>Unquoted string "offenedatei" my clash with future reserved word at
>..........
>
>Does anybody know how to handle this warning ???
>please send a e-mail mailto:wiwa@sbox.tu-graz.ac.at
>
>thanks
>walter
>
>--
>Walter Winter
>Technical University Graz
>Institute for Chemical Engineering
>Inffeldgasse 25 A-8010 Graz
>Tel: ++43/316/481300-0
>Fax: ++43/316/481300-4
>
>
------------------------------
Date: Fri, 05 Mar 1999 15:30:57 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: y2k and 4-digit dates (was Re: foreach and while)
Message-Id: <36DFEAA1.9266F325@ngb.se>
Abigail wrote:
>
> Staffan Liljas (staffan@ngb.se) wrote on MMXI September MCMXCIII in
> <URL:news:36DF0C2F.31034CAF@ngb.se>:
> __
> __ y2k is a problem if you think to narrowly and don't realise what
> __ you are assuming about the context. Even for financial programs,
> __ there is usually no problem with two digit dates, if the program
> __ was written to handle the situation of the turn of a century, since
> __ financial calculations rarely (if ever) need to run over a scope of
> __ more then 100 years.
> Oh, they certainly do. We've had exactly this problem once. Dates are
> stored internally in various y2k safe methods, but that's not the only
> problem. A entry screen for bond trades had fields for maturity dates.
> Using 2 digit years. Then one customer wanted to trade 100 year bonds,
> and suddenly 2 digit years don't suffice. And why was the entry screen
> just 2 digits wide? For the very old reason: space. There's a limited
> amount of space on a 80x24 screen. It took only a few lines of code to
> deal with entering 4 digit years, but it took major headaches to fit
> 4 digits on the screen.
Sorry. I haven't been working in the financial world at all. Where I
work four digit years are sufficient, and used _all_the_time_. But my
main point still holds... Just choose the appropriate number of digits,
for any situtation you can come up with for the application (and then I
add one, but I'm paranoid). That is always enough, if you document what
you're assuming, and program accordingly.
Staffan
------------------------------
Date: Fri, 05 Mar 1999 15:08:09 GMT
From: snowhare@long-lake.nihongo.org (Benjamin Franz)
Subject: Re: Yesterday!
Message-Id: <trSD2.162$y_2.1220@typhoon01.swbell.net>
In article <7bo8cr$8f6$1@nnrp1.dejanews.com>, <dave@mag-sol.com> wrote:
>In article <WeID2.10078$Ge3.39532024@news.itd.umich.edu>,
> mcafee@waits.facilities.med.umich.edu (Sean McAfee) wrote:
>> In article <36DF479F.379A5D5@mailexcite.com>,
>> Aaron Au <aaronau@mailexcite.com> wrote:
>> >I want to input a date code (mmddyyyy)(03011999) and output the last day
>> >format(02281999).
>> >Does anyone have a simple script?
>>
>> First, install the Date::Calc module.
>>
>> Then:
>>
>> use Date::Calc qw(Add_Delta_Days);
>>
>> sub previous_day {
>> $_[0] =~ /^(\d\d)(\d\d)(\d\d\d\d)$/;
>> sprintf("%02d%02d%04d", (Add_Delta_Days($3, $1, $2, -1))[1,2,0]);
>> }
>
>Or, using the standard Perl library.
>
>my ($d, $m, $y) - (localtime(time - 24*60*60))[3 .. 5];
>
>my $yesterday = sprintf("%02d%02d%4d", $d, $m+1, $y+1900);
There really should be a FAQ entry on why that is a _bad idea_.
Days are NOT always exactly 24*60*60 seconds long and depending
on it is unwise: POSIX to the contrary, many boxes do account
for leap seconds. 'localtime' can also can get tangled with
daylight savings shifts. There is no need to install Date::Calc
for this. The solution to edge condition problems is
to _stay away from the edges_.
#!/usr/bin/perl -w
use strict;
use Time::Local;
my ($sec,$min,$hour,$mday,$month,$year) = localtime(time);
my ($newtime) = timelocal(0,0,12,$mday,$month,$year);
($sec,$min,$hour,$mday,$month,$year) = localtime($newtime-86400);
$month++;
$year += 1900;
print "Year: $year Month: $month Day: $mday\n";
--
Benjamin Franz
------------------------------
Date: Fri, 5 Mar 1999 07:30:52 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Yesterday!
Message-Id: <MPG.11499880b51e4ca09896e7@nntp.hpl.hp.com>
In article <7bo8cr$8f6$1@nnrp1.dejanews.com> on Fri, 05 Mar 1999
09:33:15 GMT, dave@mag-sol.com <dave@mag-sol.com >says...
> > In article <36DF479F.379A5D5@mailexcite.com>,
> > Aaron Au <aaronau@mailexcite.com> wrote:
> > >I want to input a date code (mmddyyyy)(03011999) and output the last day
> > >format(02281999).
> > >Does anyone have a simple script?
...
I think by now the 'yesterday' question has achieved FAQ status!
> my ($d, $m, $y) - (localtime(time - 24*60*60))[3 .. 5];
This is relative to the present. He wants it relative to a specified
date. So,
use Time::Local;
$_ = '03011999'; # mmddyyyy
/(\d\d)(\d\d)(\d{4})/;
my $time = timelocal(0, 0, 12, $2, $1 - 1, $3 - 1900);
my ($d, $m, $y) = (localtime($time - 24*60*60))[3 .. 5];
Note that I choose local noon to shut off the usual carping about
anomalies around Summer-Time transitions.
> my $yesterday = sprintf("%02d%02d%4d", $d, $m+1, $y+1900);
And he wanted irrational US output, so switch (and season to my taste):
my $yesterday = sprintf '%.2d%.2d%d', $m + 1, $d, $y + 1900;
> --
> Dave Cross
...
Add a space after the two dashes, so newsreaders cut your .sig.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 05 Mar 1999 09:19:55 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Yesterday!
Message-Id: <m37lsv52ok.fsf@moiraine.dimensional.com>
lr@hpl.hp.com (Larry Rosler) writes:
> I think by now the 'yesterday' question has achieved FAQ status!
Not to mention out-of-the-box source code available. See
http://moiraine.dimensional.com/~dgris/cgi-bin/pfr?index=1&func=yesterday
dgris
--
Daniel Grisinger dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5065
**************************************