[18853] in Perl-Users-Digest
Perl-Users Digest, Issue: 1021 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 30 18:06:04 2001
Date: Wed, 30 May 2001 15:05:21 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <991260319-v10-i1021@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 30 May 2001 Volume: 10 Number: 1021
Today's topics:
Re: <> operator problem <mischief@velma.motion.net>
Can't get size value back when using $ftp->size (Anand Sethupathy)
Re: Controlling downloads using CGI and Apache <flavell@mail.cern.ch>
counting occurrences in a hash gjskhalsa@hotmail.com
Re: counting occurrences in a hash nobull@mail.com
Re: counting occurrences in a hash (Anno Siegel)
Re: Drat that whitespace? (Was: An Example Of A Polite <centreman_19@NOSPAMyahoo.com>
Re: good perl practice? <pawinan@ilstu.edu>
Re: How to match and print like this ??? <cadmcse@hotmail.com>
Re: How to match and print like this ??? <cadmcse@hotmail.com>
Modifying PM's <trashday@email.com>
mounting <bruedern@bauing.uni-weimar.de>
Re: mounting <jurgenex@hotmail.com>
OT: killfiles (was: Re: Perl Community Stars (?)) <elijah@workspot.net>
Re: OT: killfiles (was: Re: Perl Community Stars (?)) <godzilla@stomp.stomp.tokyo>
Re: Perl and numeric variables nobull@mail.com
Re: Perl and numeric variables <ajamtgaa@cisco.com>
Re: Perl and numeric variables <godzilla@stomp.stomp.tokyo>
Re: Perl and numeric variables <godzilla@stomp.stomp.tokyo>
Re: Perl Community Stars (?) MSherrill@compuserve.com
Re: Perl Community Stars (?) <mischief@velma.motion.net>
Re: Perl excercises <lglessner@hotmail.com>
Re: Perl excercises nobull@mail.com
Re: Perl excercises <lglessner@hotmail.com>
Re: Perl excercises <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 30 May 2001 20:20:56 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: <> operator problem
Message-Id: <thalh8r7u83l02@corp.supernews.com>
Risto Vaarandi <risto.vaarandi@eyp.ee> wrote:
> hello,
> I am trying to tail a file with a perl program. The program just opens
You could get strange results due to end-of-file being read and such.
You might want to use seek(). Or, check the FAQ.
$ perldoc -q tail
=head1 Found in /usr/lib/perl5/5.00503/pod/perlfaq5.pod
=head2 How do I do a C<tail -f> in perl?
First try
seek(GWFILE, 0, 1);
The statement C<seek(GWFILE, 0, 1)> doesn't change the current position,
but it does clear the end-of-file condition on the handle, so that the
next <GWFILE> makes Perl try again to read something.
If that doesn't work (it relies on features of your stdio implementation),
then you need something more like this:
for (;;) {
for ($curpos = tell(GWFILE); <GWFILE>; $curpos = tell(GWFILE)) {
# search for some stuff and put it into files
}
# sleep for a while
seek(GWFILE, $curpos, 0); # seek to where we had been
}
If this still doesn't work, look into the POSIX module. POSIX defines
the clearerr() method, which can remove the end of file condition on a
filehandle. The method: read until end of file, clearerr(), read some
more. Lather, rinse, repeat.
There's also a File::Tail module from CPAN.
Chris
--
#!/usr/bin/perl
$z = int(rand(1000)+1); $y = 'reverse ' x $z;
eval eval qq{$y "@{['\"n\\\\.rekcaH','lreP','rehtonA','tsuJ\"','tnirp']}"}
------------------------------
Date: 30 May 2001 14:21:08 -0700
From: as@inaday.com (Anand Sethupathy)
Subject: Can't get size value back when using $ftp->size
Message-Id: <a7ad49a1.0105301321.56e38baf@posting.google.com>
Hi,
We have a perl script that transports large data files between Windows
and Linux machines. For some reason, we can't seem to read the file
size on files that reside on the Windows FTP Server (IIS4.0/NTSP6a).
It just returns "" for the size each time. Any thoughts on what might
be causing this?
$ftp = Net::FTP->new($get_machine, Debug => 0);
$status = $ftp->login($username,$password);
print "Getting File\n";
$status = $ftp->get($file);
print "Status: $status\n";
Any advice would be greatly appreciated.
Thanks
------------------------------
Date: Wed, 30 May 2001 20:21:12 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Controlling downloads using CGI and Apache
Message-Id: <Pine.LNX.4.30.0105302006140.3903-100000@lxplus003.cern.ch>
On 30 May 2001, Rafael Garcia-Suarez wrote:
> Dave wrote in comp.lang.perl.misc:
> }
> } We have a site which will serve as a document repository. We need to
> } prevent users from getting to the files directly (i.e. type in full URL to
> } file).
This is a straightforward WWW question - that really has nothing to do
with the topic of c.l.perl.misc.
If they're to be prevented from accessing the full URL, then it's hard
to see what's wrong with putting access control on that URL.
> } One way to prevent this is to redirect the user to a CGI script for
> } authentication/authorisation.
Re-inventing the wheel in this way should probably be the last resort,
and only when a convincing argument has been supplied for not using
the web's built-in protocols.
[If you're worried about network sniffing of credentials then you
could insist on https being used. Whether this is useful depends on
circumstances and needs. If you insist on designing your own method
over unencrypted http then you may well be creating security
exposures.]
> Here's a framework you can use :
>
> Place the files to be downloaded outside of the directories served by
> apache. Your CGI script should check user authorisation, and then, if
> successful, print the appropriate headers (probably Content-Type:
> application/octet-stream) and copy the chosen file to the standard
> output.
I'm not saying that it won't work - clearly it can. But why do this?
I've got a feeling that people typically get de-railed when they get
the idea that "downloading" is something special. In WWW terms, it
isn't. The client presents a request, the server returns a result
with a server-determined content-type; the client examines the
content-type and decides what to do with it (ask the user, display in
browser, fire-up external application, offer to save to disk)
according to the user's configuration and wishes.
All proper WWW transactions proceed like this: all retrieved content
is "downloaded", otherwise it couldn't be viewed. Ergo, whatever
techniques are appropriate for controlled viewing of web pages are
also appropriate for controlled retrieval of resources to file.
> Note that this can be implemented in many other langages; your question
> is not Perl-specific,
Fully concur with that.
------------------------------
Date: Wed, 30 May 2001 12:00:50 -0700
From: gjskhalsa@hotmail.com
Subject: counting occurrences in a hash
Message-Id: <3B154362.47203117@hotmail.com>
Hi folks,
I am trying unsucessfully to extract information from a multidimensional
array and create a new hash from trhat information. I have this:
---
#!/usr/bin/perl
$hash{one} = {
elem1 => '33',
elem2 => '46',
elem3 => 'cat',
elem4 => '53',
};
$hash{two} = {
elem1 => '35',
elem2 => '43',
elem3 => 'dog',
elem4 => '57',
};
$hash{three} = {
elem1 => '35',
elem2 => '43',
elem3 => 'dog',
elem4 => '57',
};
__EOF__
Therefrom, I'd like to be able to to create a new hash, which is created
by counting the unique occurences of $hash{$key}{elem3}, so I could see
that 'dog' occurs twice :
new_hash = {
cat => '1',
dog => '2'.
};
Ideally, I'd like to know that it was $hash{two} and $hash{three} that
conatined 'dog' in 'elem3' and likewise for 'cat'; but I could contrive
something after the fact to figure that out I suppose. Here is what I
have so far, which does not give me a satisfatory output:
# foreach key in $hash ....
push ( @elems, $hash{$key}{elem3} );
#and then send to a subroutine
foreach $elem(@elems) {
$match =~ /\w\w\w/; #match against a three letter word
$array2{$1}++;
}
foreach $amt (sort keys %array2) {
print "$amt - - $array2{$amt} \n";
}
__EOF__
Which doesn't really work, because the keys of %array2 are undef. Can
anyone help me out? What is the best way to do this? Thanks for your
time.
Gurujiwan
------------------------------
Date: 30 May 2001 20:31:59 +0100
From: nobull@mail.com
Subject: Re: counting occurrences in a hash
Message-Id: <u966eibplc.fsf@wcl-l.bham.ac.uk>
gjskhalsa@hotmail.com writes:
> $hash{one} = {
> elem1 => '33',
> elem2 => '46',
> elem3 => 'cat',
> elem4 => '53',
> };
>
> $hash{two} = {
> elem1 => '35',
> elem2 => '43',
> elem3 => 'dog',
> elem4 => '57',
> };
>
> $hash{three} = {
> elem1 => '35',
> elem2 => '43',
> elem3 => 'dog',
> elem4 => '57',
> };
>
> __EOF__
>
> Therefrom, I'd like to be able to to create a new hash, which is created
> by counting the unique occurences of $hash{$key}{elem3}, so I could see
> that 'dog' occurs twice :
>
> new_hash = {
> cat => '1',
> dog => '2'.
> };
So that would be:
my $new_hash = {};
$new_hash->{$_->{elem3}}++ for values %hash;
> Ideally, I'd like to know that it was $hash{two} and $hash{three} that
> conatined 'dog' in 'elem3' and likewise for 'cat'
So that would be:
my $new_hash = {};
push @{$new_hash->{$hash{$_}{elem3}}}, $_ for keys %hash;
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 30 May 2001 19:57:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: counting occurrences in a hash
Message-Id: <9f3jb6$pn6$1@mamenchi.zrz.TU-Berlin.DE>
According to <gjskhalsa@hotmail.com>:
> Hi folks,
>
> I am trying unsucessfully to extract information from a multidimensional
> array and create a new hash from trhat information. I have this:
> ---
> #!/usr/bin/perl
>
> $hash{one} = {
> elem1 => '33',
> elem2 => '46',
> elem3 => 'cat',
> elem4 => '53',
> };
>
> $hash{two} = {
> elem1 => '35',
> elem2 => '43',
> elem3 => 'dog',
> elem4 => '57',
> };
>
> $hash{three} = {
> elem1 => '35',
> elem2 => '43',
> elem3 => 'dog',
> elem4 => '57',
> };
>
> __EOF__
It's good to present data that can be immediately used. A my()
declaration for %hash would have been a bonus.
> Therefrom, I'd like to be able to to create a new hash, which is created
> by counting the unique occurences of $hash{$key}{elem3}, so I could see
> that 'dog' occurs twice :
> new_hash = {
> cat => '1',
> dog => '2'.
> };
>
(You forgot a "%" in front of "new_hash".)
$new_hash{ $_->{ elem3}}++ for values %hash;
That doesn't even look at the keys of your hash. Instead it walks
through the hash references that are its values and counts up
$new_hash according to what it finds in the "elem3" position.
> Ideally, I'd like to know that it was $hash{two} and $hash{three} that
> conatined 'dog' in 'elem3' and likewise for 'cat'; but I could contrive
> something after the fact to figure that out I suppose. Here is what I
> have so far, which does not give me a satisfatory output:
You could store a list of the keys for which each animal is met
instead of merely counting the occurrences. In that case, we do
need the keys of the original array, so let's re-write the bit of
code above so that the keys are known:
$new_hash{ $hash{ $_}->{ elem3}}++ for keys %hash;
Now, instead of counting, lets assume array references in the
value slots of $new_hash; auto-vivification will make it true.
We simply push the key in $_ onto the assumed array:
push @{ $new_hash{ $hash{ $_}->{ elem3}}}, $_ for keys %hash;
To see the result, you can
print "$_ => @{ $new_hash{ $_}}\n" for keys %new_hash;
which will print
cat => one
dog => three two
[rest snipped]
Anno
------------------------------
Date: Wed, 30 May 2001 12:11:41 -0700
From: "Brandon Thornburg" <centreman_19@NOSPAMyahoo.com>
Subject: Re: Drat that whitespace? (Was: An Example Of A Polite FAQ)
Message-Id: <9f3gm4$8no$1@fremont.ohsu.edu>
Actually, from where I'm sitting, you'd end up with more of a Before Posting
Hear- HERE MEANS YOU effect. Kind of an All Your Base sort of vibe.
Brandon
> >>Before Posting Hear - THIS MEANS YOU.
> > ^^^^
> >
> >Shouldn't that be "Here"?
>
> Hmmm... I suppose that
>
> Before Posting Hear - THIS MEANS Here
>
> _is_ a bit of an improvement. ;-)
------------------------------
Date: 30 May 2001 19:34:59 GMT
From: Phil Winans <pawinan@ilstu.edu>
Subject: Re: good perl practice?
Message-Id: <9f3i13$odu$1@news.ilstu.edu>
Willem <usenet@willem.byte.nl> wrote:
> Imagine the following example, is this the preferred way of checking for
> errors within subs?
> If not, how could this be written more smoothly?
> db_connect() or die "DB connection failed";
> sub db_connect {
> use DBI;
> $dbh = DBI->connect("DBI:mysql:byte:host","user","bla");
> if ($dbh) {
> return 0;
> } else {
> warn "Could not connect to dbase: ".DBI->errstr;
> return 1;
> }
> }
The extra warning is redundant here. If there was a problem connecting
to your database, you would have three error messages. Suppose there
is no database 'byte' on your host.
When DBI->connect fails, you'll get output similar to:
(1) DBI->connect() failed: FATAL 1: Database "byte" does not exist in
the system catalog. at whatever.pl line 4.
(2) Could not connect to dbase: FATAL 1: Database "byte" does not exist
in system catalog. at whatever.pl line 7.
(3) DB connection failed at whatever.pl line 1.
When you instantiate a DBI object, it possesses an attribute called
"PrintError" which is by default set to 1. When this attribute is set
and one of your DBI object methods fails, 'warn $DBI::errstr' or similar
is called. This will give you warning (1).
You then wrote in your db_connect sub to warn if your object $dbh could
not be instantiated. That's where you get warning (2).
Finally, if db_connect didn't work, your program is supposed to die.
This gives you message (3).
I think there are too many warnings here. If you want to write your own
error messages, I suggest turning PrintError off, which can be achieved
by calling connect like this: $dbh = DBI->connect("DBI:mysql:byte:host",
"user","bla", { PrintError => 0 }); That eliminates error message 1.
When the flow of my program is dependent on successful execution of
each DBI object method, I like to set the RaiseError attribute on.
RaiseError will cause a 'die' whenever an object method fails, so I
don't have to explicitly write something like "$sth->execute or die
$DBI::errstr" everytime I call an object method.
So, I do things like:
eval {
$dbh = DBI->connect("DBI:Pg:dbname=foo;host=127.0.0.1",
"myname", "mypass", { PrintError => 0})
|| die $DBI::errstr;
$dbh->{RaiseError} = 1;
$sth->prepare("select * from mytable");
$sth->execute;
# etc. etc.
};
if ($dbh) {
$dbh->disconnect;
}
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head><title>My Page</title></head>\n";
if ($@) { # If we had errors
chomp $@;
print "<body>Couldn't retrieve info<br><b>", $@, "</b></body>";
} else {
print "<body>Here's what I pulled out of the db<br>", $data, "</body>";
}
print "</html>";
exit;
This is very useful in CGI scripts when you need more control over
your program output.
---
Phil Winans / pawinan@ilstu.edu
------------------------------
Date: Wed, 30 May 2001 11:59:06 -0700
From: "cadfei" <cadmcse@hotmail.com>
Subject: Re: How to match and print like this ???
Message-Id: <9f3ff2$25c$1@taliesin.netcom.net.uk>
THanks for help,
I had almost done the program, except this problem..
In order easy to import output by use Microsoft Excel
I plan to put "\t"(tag) between First colum and last one,
(evey output line between first and last element)
But I do have difficulty to modify the print format method u show me ..
because I am not good in hash:(
Could u teach me or explain the code below ?
Thanks!!
for my $x ( sort keys %graph ) {
printf "%${mast_wid}s", $x;
for my $y ( @masters ) {
printf "%${col_wid}s", exists $graph{$x}{$y} ? $graph{$x}{$y} :
' ';
}
print "\n";
"John W. Krahn" <krahnj@acm.org> wrote in message
news:3B12E537.14B75373@acm.org...
> cad fei wrote:
> >
> > "John W. Krahn" <krahnj@acm.org>
> > > #!/usr/bin/perl -w
> > > use strict;
> > >
> > > my %graph;
> > > my @masters;
> > > my $mast_wid = 0;
> > > my $col_wid = 0;
> > > while ( <DATA> ) {
> > > my @f = split " ";
> > > my $master = shift @f;
> > > my $instance = pop @f;
> > > push @masters, $master;
> > > $mast_wid = length $master if $mast_wid < length $master;
> > >
> > > for ( @f ) {
> > > $graph{ $_ }{ $master } = substr $master, 0, 1;
> > > $col_wid = length if $col_wid < length;
> > > }
> > > }
> > > $col_wid++;
> > > $mast_wid++;
> > >
> > > printf "%${mast_wid}s" . "%${col_wid}s" x @masters . "\n", ' ',
> > > @masters;
> > > for my $x ( sort keys %graph ) {
> > > printf "%${mast_wid}s", $x;
> > > for my $y ( @masters ) {
> > > printf "%${col_wid}s", exists $graph{$x}{$y} ? $graph{$x}{$y}
: ' ';
> > > }
> > > print "\n";
> > > }
> > >
> >
------------------------------
Date: Wed, 30 May 2001 14:03:38 -0700
From: "cadfei" <cadmcse@hotmail.com>
Subject: Re: How to match and print like this ???
Message-Id: <9f3moj$dis$1@taliesin.netcom.net.uk>
sorry, I mean every element come with \t
can I put "\t" in somewhere in printf?
printf "%${col_wid}s", exists $graph{$x}{$y} ? $graph{$x}{$y} :
"cadfei" <cadmcse@hotmail.com> wrote in message
news:9f3ff2$25c$1@taliesin.netcom.net.uk...
>
> THanks for help,
> I had almost done the program, except this problem..
> In order easy to import output by use Microsoft Excel
> I plan to put "\t"(tag) between First colum and last one,
> (evey output line between first and last element)
> But I do have difficulty to modify the print format method u show me ..
> because I am not good in hash:(
> Could u teach me or explain the code below ?
> Thanks!!
>
> for my $x ( sort keys %graph ) {
> printf "%${mast_wid}s", $x;
> for my $y ( @masters ) {
> printf "%${col_wid}s", exists $graph{$x}{$y} ? $graph{$x}{$y}
:
> ' ';
> }
> print "\n";
>
>
> "John W. Krahn" <krahnj@acm.org> wrote in message
> news:3B12E537.14B75373@acm.org...
> > cad fei wrote:
> > >
> > > "John W. Krahn" <krahnj@acm.org>
> > > > #!/usr/bin/perl -w
> > > > use strict;
> > > >
> > > > my %graph;
> > > > my @masters;
> > > > my $mast_wid = 0;
> > > > my $col_wid = 0;
> > > > while ( <DATA> ) {
> > > > my @f = split " ";
> > > > my $master = shift @f;
> > > > my $instance = pop @f;
> > > > push @masters, $master;
> > > > $mast_wid = length $master if $mast_wid < length $master;
> > > >
> > > > for ( @f ) {
> > > > $graph{ $_ }{ $master } = substr $master, 0, 1;
> > > > $col_wid = length if $col_wid < length;
> > > > }
> > > > }
> > > > $col_wid++;
> > > > $mast_wid++;
> > > >
> > > > printf "%${mast_wid}s" . "%${col_wid}s" x @masters . "\n", ' ',
> > > > @masters;
> > > > for my $x ( sort keys %graph ) {
> > > > printf "%${mast_wid}s", $x;
> > > > for my $y ( @masters ) {
> > > > printf "%${col_wid}s", exists $graph{$x}{$y} ?
$graph{$x}{$y}
> : ' ';
> > > > }
> > > > print "\n";
> > > > }
> > > >
> > >
>
>
------------------------------
Date: Wed, 30 May 2001 16:12:24 -0600
From: Todd Anderson <trashday@email.com>
Subject: Modifying PM's
Message-Id: <3B157040.2AAB6E7F@email.com>
I just started working with perl modules. I downloaded a free script and
I can't open the module in my text editor to modify it. I'm ussing MS
Works for MAC. Any ideas?
------------------------------
Date: Wed, 30 May 2001 20:20:34 +0200
From: "Arnd-Eike Brüdern" <bruedern@bauing.uni-weimar.de>
Subject: mounting
Message-Id: <9f3do8$2t3$1@tigger.scc.uni-weimar.de>
Hi all,
is it possible with a perlskript to mount a samba-share from server.
Thanks all.
------------------------------
Date: Wed, 30 May 2001 12:51:21 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: mounting
Message-Id: <3b154f48$1@news.microsoft.com>
"Arnd-Eike Brüdern" <bruedern@bauing.uni-weimar.de> wrote in message
news:9f3do8$2t3$1@tigger.scc.uni-weimar.de...
> is it possible with a perlskript to mount a samba-share from server.
I don' think so (why would anybody want to re-invent the wheel?).
But of course you can always call the OS-specific external "mount" commands
from your Perl script.
jue
------------------------------
Date: 30 May 2001 18:53:04 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: OT: killfiles (was: Re: Perl Community Stars (?))
Message-Id: <eli$0105301449@qz.little-neck.ny.us>
In comp.lang.perl.misc, Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> Abigail <abigail@foad.org> wrote:
> > Several movies have been made about Godzilla.
> Yes, but I wouldn't really classify her as a Perl person, more as a
> cargo-cult misinformant. Or has she improved since my killfile started
> taking care of threads containing posts from her?
You killfile the whole thread? Or all followups?
I've been killing the posts and the immediate follow-ups. In trn4
killfile syntax:
/@stomp.stomp.tokyo/HFrom:j
/@stomp.stomp.tokyo/HMessage-ID:j
/@stomp.stomp.tokyo>$/HReferences:j
Elijah
------
kills only on overview headers whenever possible
------------------------------
Date: Wed, 30 May 2001 12:08:03 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: OT: killfiles (was: Re: Perl Community Stars (?))
Message-Id: <3B154513.D3FDB8C5@stomp.stomp.tokyo>
Eli the Bearded wrote:
> Martien Verbruggen wrote:
> > Abigail wrote:
> > > Several movies have been made about Godzilla.
> > Yes, but I wouldn't really classify her as a Perl person, more as a
> > cargo-cult misinformant. Or has she improved since my killfile started
> > taking care of threads containing posts from her?
> You killfile the whole thread? Or all followups?
> I've been killing the posts and the immediate follow-ups. In trn4
> killfile syntax:
> /@stomp.stomp.tokyo/HFrom:j
> /@stomp.stomp.tokyo/HMessage-ID:j
> /@stomp.stomp.tokyo>$/HReferences:j
You are very efficient with your hatred. I'm impressed
with such talent. Perhaps many will follow your lead
and gain greater enlightenment.
Godzilla!
------------------------------
Date: 30 May 2001 18:55:46 +0100
From: nobull@mail.com
Subject: Re: Perl and numeric variables
Message-Id: <u9n17ubu1p.fsf@wcl-l.bham.ac.uk>
"Prasad, Victor [FITZ:K500:EXCH]" <vprasad@americasm01.nt.com> writes:
> I am passing some input from an html form.
>
> It is received to a perl file. Is there anyway I can force the data to
> be numeric.
Add zero to it.
$value += 0;
> ie. is the number 1 a number or character.
The number 1 is a number. The character 1 is a character but Perl has
no explict character type. The string "1" is a string.
> Is there a define or a special numeric variable holder?
Not in Perl5. Perl6 will IIRC have typed variables.
> Or transposed commmand?
I have no idea what you meant by that.
Perhaps this would all make more sense if we had some idea why you
think it matters.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 30 May 2001 12:15:21 -0600
From: Arne Jamtgaard <ajamtgaa@cisco.com>
Subject: Re: Perl and numeric variables
Message-Id: <3B1538B9.F51E577@cisco.com>
"Prasad, Victor [FITZ:K500:EXCH]" wrote:
> I am passing some input from an html form.
> It is received to a perl file.
I assume you mean 'calls a perl script.'
> Is there anyway I can force the data to be numeric.
> ie. is the number 1 a number or character.
> Is there a define or a special numeric variable holder? Or transposed
> commmand?
A short, perl answer is "Nope." You can check a string for strictly
numeric content, though. Study up on regular expressions, and the rest
should be pretty strightforward.
Arne
------------------------------
Date: Wed, 30 May 2001 11:41:41 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Perl and numeric variables
Message-Id: <3B153EE5.AFC810D5@stomp.stomp.tokyo>
Prasad, Victor wrote:
> I am passing some input from an html form.
> It is received to a perl file. Is there anyway I can force the data to
> be numeric.
> ie. is the number 1 a number or character.
> Is there a define or a special numeric variable holder? Or transposed
> commmand?
You are not very clear with your parameters. I am making
a presumption your input is strictly numerical digits.
Perl has an exceptionally handy feature which allows you
to change what we normally consider a number into a plain
character. Otherwords, you can treat a numerical digit
as either a number or a character. This is accomplished
with easy syntax.
Look over my test script and carefully note my syntactic
use of,
eq
==
and quote marks
You will note how easy it is to switch between number
treatment and character treatment.
Godzilla!
--
#!perl
$input_key{value} = "1";
if ($input_key{value} eq "1")
{
print "if (\$input_key{value} eq \"1\") \n",
"This is treated as a character\n\n";
$number = "$input_key{value} + $input_key{value}";
print "\$number = \"\$input_key{value} + \$input_key{value}\"\n",
"will produce: $number";
}
print "\n\n\n";
if ($input_key{value} == 1)
{
print "if (\$input_key{value} == 1) \n",
"This is treated as a number\n\n";
$number = $input_key{value} + $input_key{value};
print "\$number = \$input_key{value} + \$input_key{value}\n",
"will produce: $number";
}
PRINTED RESULTS:
________________
if ($input_key{value} eq "1")
This is treated as a character
$number = "$input_key{value} + $input_key{value}";
will produce: 1 + 1
if ($input_key{value} == 1)
This is treated as a number
$number = $input_key{value} + $input_key{value};
will produce: 2
------------------------------
Date: Wed, 30 May 2001 12:03:27 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Perl and numeric variables
Message-Id: <3B1543FF.8FE3777D@stomp.stomp.tokyo>
"Godzilla!" wrote:
oops.. I made some changes in my test script to include
printed semicolons and forget to make those changes in
my code presented in my article.
> print "\$number = \"\$input_key{value} + \$input_key{value}\"\n",
> "will produce: $number";
Change to:
print "\$number = \"\$input_key{value} + \$input_key{value}\";\n",
"will produce: $number";
> print "\$number = \$input_key{value} + \$input_key{value}\n",
> "will produce: $number";
Change to:
print "\$number = \$input_key{value} + \$input_key{value};\n",
"will produce: $number";
Godzilla!
------------------------------
Date: Wed, 30 May 2001 18:27:46 GMT
From: MSherrill@compuserve.com
Subject: Re: Perl Community Stars (?)
Message-Id: <3b153a02.18941967@news.compuserve.com>
On Tue, 29 May 2001 09:27:00 -0400, Lou Moran <lmoran@wtsg.com> wrote:
[snip]
>There doesn't seem to be a star in the Lotus Notes world.
You might be confusing Usenet newsgroups with communities. There are
noteworthy authors in the Lotus Notes world, and some of them have an
online community. But their community isn't on Usenet.
--
Mike Sherrill
Information Management Systems
------------------------------
Date: Wed, 30 May 2001 20:59:57 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Perl Community Stars (?)
Message-Id: <thanqdj5b32156@corp.supernews.com>
Lou Moran <lmoran@wtsg.com> wrote:
> --I have noticed that Perl seems to have "famous" people.
[snip]
> --I don't notice this in other languages/computer systems so much.
[snip]
> --Are there other famous programmers in other languages or is this a
> "Perl Thing"?
Alan Cox comes to mind for Linux. W. Richard Stevens comes to
mind for TCP/IP network programming. RMS and ESR are known by
their initials, for crying out loud. I'd call _that_ famous.
The FSF / the GNU project is a community, too, remember. There
are famous people in every computer-related community, just like
in every IRL community. Heck, there are even famous players of
certain popular computer games, just like they were professional
athletes. Each application domain has famous people, too.
I think one reason there are so many well-known people in the
Perl community is because the language is so vast. It takes
someone with an exceptional knowledge of the language to know
the best ways to do a wide range of things. In C, you can
consult Knuth then write code that optimizes well. In Perl,
there's room for many people to contribute many ways to do the
same thing to the same group, and to have nearly equally
performing implementations.
Chris
P.S., here's my first JAPH:
--
#!/usr/bin/perl
$z = int(rand(1000)+1); $y = 'reverse ' x $z;
eval eval qq{$y "@{['\"n\\\\.rekcaH','lreP','rehtonA','tsuJ\"','tnirp']}"}
------------------------------
Date: Wed, 30 May 2001 19:19:44 GMT
From: "Lynn" <lglessner@hotmail.com>
Subject: Re: Perl excercises
Message-Id: <kJbR6.3248$651.171125@newsread1.prod.itd.earthlink.net>
I've been lurking for months and haven't seen a question I was confident
enough to answer yet, but my day will come .....
Lynn
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9h9lj0.2gt.tadmc@tadmc26.august.net...
> dot-comet <cometlinear@yahoo.com> wrote:
> >
> >Can anyone recommend and websites which have Perl "homework
> >assignments" (excercises) for beginner-intermediate level. I've got to
> >keep my blade sharp...
>
>
> I dunno about web sites, but there are newsgroups which daily pose
> Perl problems to be solved...
>
> Answer Perl questions here. Help your peers. See how others would
> solve the same problem. Get your answers critiqued by many others.
> Learn Perl.
>
> :-)
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
>
------------------------------
Date: 30 May 2001 20:37:15 +0100
From: nobull@mail.com
Subject: Re: Perl excercises
Message-Id: <u93d9mbpck.fsf@wcl-l.bham.ac.uk>
"Lynn" <lglessner@hotmail.com> writes in untrimmed jeopary style:
> I've been lurking for months and haven't...
...figured out that posting in untrimmed jeopary style is
considered very rude?
> ...seen a question I was confident enough to answer yet, but my day
> will come .....
You can build up you confidence by answering FAQs! There's no work
required, just have the FAQ next to you and when someone posts a Q
from the FAQ just tell them which FAQ it is.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 30 May 2001 21:30:03 GMT
From: "Lynn" <lglessner@hotmail.com>
Subject: Re: Perl excercises
Message-Id: <vDdR6.3477$651.193814@newsread1.prod.itd.earthlink.net>
<nobull@mail.com> wrote in message news:u93d9mbpck.fsf@wcl-l.bham.ac.uk...
> "Lynn" <lglessner@hotmail.com> writes in untrimmed jeopary style:
>
> > I've been lurking for months and haven't...
> ...figured out that posting in untrimmed jeopary style is
> considered very rude?
You're right, I haven't figured it out. I personally *like* people to post
the reply at the top so I don't have to scroll down. I have seen people
complain about "top-posting" before, though, so I guess I'm in the minority.
I'll just try and remember to put my answer at the bottom even though it
makes no sense to me - just do it.
The one unspoken rule that I have internalized is not to have a sig line
more than four lines, though ;)
I like the FAQ idea, and will try that.
Lynn
------------------------------
Date: Wed, 30 May 2001 21:53:43 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl excercises
Message-Id: <7qqahtcp2neajs06ckq6523plnl9hrmu4a@4ax.com>
Lynn wrote:
> I personally *like* people to post
>the reply at the top so I don't have to scroll down.
Oh no, not again.
I've recently seen posts of 200 lines. I had to scroll just to see, if
anything new was added. That wasn't obvious through the "quoting"
mechanism, which, again, wasn't standard. Instead, it was just a *copy*
of the original post. A lot of work for me, and it turned out to be all
for nothing.
If you want to spare people having to scroll through tons of useless
quoting, then DON'T QUOTE.
Do not ever quote anything that is irrelevant. That's the rule.
--
Bart.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
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 1021
***************************************