[19250] in Perl-Users-Digest
Perl-Users Digest, Issue: 1445 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 5 00:05:31 2001
Date: Sat, 4 Aug 2001 21:05:06 -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: <996984306-v10-i1445@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 4 Aug 2001 Volume: 10 Number: 1445
Today's topics:
Re: Additional questions (Alan Barclay)
Re: Additional questions <Tassilo.Parseval@post.rwth-aachen.de>
Re: Additional questions <krahnj@acm.org>
Re: automatic array elements <godzilla@stomp.stomp.tokyo>
Re: automatic array elements <Tassilo.Parseval@post.rwth-aachen.de>
Re: automatic array elements (Tad McClellan)
Re: Call Javascript from Perl <ron@savage.net.au>
CGI.pm file upload problem - Please Help! <Gala@nonono.com>
Re: CGI.pm file upload problem - Please Help! <ron@savage.net.au>
Re: comp.infosystems.www.authoring.cgi now moderated <revjack@revjack.net>
Re: comp.infosystems.www.authoring.cgi now moderated <SEE_MY_SIG@nospam.demon.co.uk>
Re: comp.infosystems.www.authoring.cgi now moderated <revjack@revjack.net>
Re: How can I download a file and stroke a counter at t <goldbb2@earthlink.net>
Re: Howto run traceroute-parse IP's-store in array? (Adam)
prompting and redirection with ssh <billy_dont_try@verizon.net>
Re: reading and writing arrays <Tassilo.Parseval@post.rwth-aachen.de>
Re: serial ports/modems and chat2.pl (Alan Barclay)
using eval (Ken)
Re: using eval (Clinton A. Pierce)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 5 Aug 2001 00:59:17 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Additional questions
Message-Id: <996973139.375261@elaine.furryape.com>
In article <Ku_a7.28121$b_3.2282979@news0.telusplanet.net>,
Sean Hamilton <sh@planetquake.com> wrote:
>Two additional questions.
>
>1. How does "print" work, in that it allows an argument to be specified, and
>if one is not, it defaults to $_? How would myprint be written to do this?
>Must I declare two primts, one of which calls the other with $_?
Something like this does the trick.
sub myprint {
my $x;
if(@_){
$x=shift;
} else {
$x=$_
}
print "$x\n";
}
Or, somewhat more concisly:
sub doit {
my $x=$_;
$x=shift if(@_);
print "$x\n";
}
------------------------------
Date: Sun, 05 Aug 2001 04:20:06 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Additional questions
Message-Id: <3B6CAD56.5010302@post.rwth-aachen.de>
Alan Barclay wrote:
>In article <Ku_a7.28121$b_3.2282979@news0.telusplanet.net>,
>Sean Hamilton <sh@planetquake.com> wrote:
>
>>Two additional questions.
>>
>>1. How does "print" work, in that it allows an argument to be specified, and
>>if one is not, it defaults to $_? How would myprint be written to do this?
>>Must I declare two primts, one of which calls the other with $_?
>>
>
>Something like this does the trick.
>
No, it does not.
>
>
>sub myprint {
> my $x;
> if(@_){
> $x=shift;
> } else {
> $x=$_
>
$x now will always be empty if the else-branche is executed.
>
> }
> print "$x\n";
>}
>
>Or, somewhat more concisly:
>
>sub doit {
> my $x=$_;
> $x=shift if(@_);
> print "$x\n";
>}
>
Still very suspect. Mark this: $_ does not contain the first argument to
the subroutine call. It is just empty. Arguments are to be found in @_,
so the first argument is $_[0].
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Sun, 05 Aug 2001 03:51:50 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Additional questions
Message-Id: <3B6CC334.91076946@acm.org>
Alan Barclay wrote:
>
> In article <Ku_a7.28121$b_3.2282979@news0.telusplanet.net>,
> Sean Hamilton <sh@planetquake.com> wrote:
> >Two additional questions.
> >
> >1. How does "print" work, in that it allows an argument to be specified, and
> >if one is not, it defaults to $_? How would myprint be written to do this?
> >Must I declare two primts, one of which calls the other with $_?
>
> Something like this does the trick.
>
> sub myprint {
> my $x;
> if(@_){
> $x=shift;
> } else {
> $x=$_
> }
> print "$x\n";
> }
>
> Or, somewhat more concisly:
>
> sub doit {
> my $x=$_;
> $x=shift if(@_);
> print "$x\n";
> }
What if you want to print a list like print, or use file habdles?
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 04 Aug 2001 18:11:52 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: automatic array elements
Message-Id: <3B6C9D58.A82C9122@stomp.stomp.tokyo>
Tassilo von Parseval wrote:
> Les Ander wrote:
> >i would like to build an array automatically.
> > i know that @arr=(1..10) fills the @arr with elements 1 to 10.
> >But i want to fill @arr with elements from 10..100 with every 10th
> >elements. For example in matlab i can say a=[10:10:100]
> >which will make a=(10, 20, 30, ..,100)
> >Can i do some thing similar with perl (i.e. can i give an arbitrary
> >increment to fill up the array?)
> You could do it thus:
> my @array;
> $array[$_ * 10] for (1 .. 10);
#!perl
print "Content-type: text/plain\n\n";
my @array;
$array[$_ * 10] for (1 .. 10);
if (@array)
{ print "@array"; }
else
{ print "Your Code Is FUBAR"; }
PRINTED RESULTS:
________________
Your Code Is FUBAR
Godzilla!
------------------------------
Date: Sun, 05 Aug 2001 03:13:57 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: automatic array elements
Message-Id: <3B6C9DD5.1020407@post.rwth-aachen.de>
Godzilla! wrote:
>Tassilo von Parseval wrote:
>
>
>>You could do it thus:
>>my @array;
>>$array[$_ * 10] for (1 .. 10);
>>
>
>
>#!perl
>
>print "Content-type: text/plain\n\n";
>
>my @array;
>$array[$_ * 10] for (1 .. 10);
>
>if (@array)
> { print "@array"; }
>else
> { print "Your Code Is FUBAR"; }
>
>
>PRINTED RESULTS:
>________________
>
>Your Code Is FUBAR
>
Correct, as I already pointed out in the replie to myself.
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Sat, 4 Aug 2001 22:27:22 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: automatic array elements
Message-Id: <slrn9mpboa.47a.tadmc@tadmc26.august.net>
Les Ander <citykid@nospam.edu> wrote:
>i would like to build an array automatically.
> i know that @arr=(1..10) fills the @arr with elements 1 to 10.
>
>But i want to fill @arr with elements from 10..100 with every 10th
>elements. For example in matlab i can say a=[10:10:100]
>which will make a=(10, 20, 30, ..,100)
So you want to map (transform) the values, eh?
>Can i do some thing similar with perl (i.e. can i give an arbitrary
>increment to fill up the array?)
You can use map() to make all kinds of transformations of lists.
Your application is one of the very simplist of transforms:
my @arr = map { $_ * 10 } 1..10;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 5 Aug 2001 13:28:42 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: Call Javascript from Perl
Message-Id: <E63b7.4447$257.197569@ozemail.com.au>
Xingfu
See below.
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
Xingfu Wu <wuxf@ece.northwestern.edu> wrote in message news:3B6B1001.5483E73E@ece.northwestern.edu...
> I use CGI.pm to pass a variable value to Javascript, I need to pass a
> variable value from Javascript to Perl. I heard that PerlConnect of
> mozilla.org can do that, but I do not know where I can get the version
> for linux.
Any Perl script can pass data back and forth between Perl variables and JavaScript variables.
See tut 39 for a demo: http://savage.net.au/Perl-tutorials.html
------------------------------
Date: Sun, 05 Aug 2001 01:23:43 GMT
From: "Gala" <Gala@nonono.com>
Subject: CGI.pm file upload problem - Please Help!
Message-Id: <ze1b7.31269$Kd7.19120199@news1.rdc1.sfba.home.com>
Hi, I've been working on a upload script but have not been able to get this to work. I'm been working weeks trying to get
this to work. I've looked through the active-perl html docs & groups.google.com furiously through mounds of exmples and such
to no avail. I am delevoping and testing it on my computer, which runs win98se, PWS 4 with Active-Perl 5.005_03. (All my
other scripts run just fine, after I did some registry tweeking to get perl to work with pws in the first place ;p)
--The Problem-- After submiting the form, the browser turns white and just stops. If I comment out line 22 (with the
upload() ) it prints File... just fine. But the file DID upload... to the tmp dir on line 2, and is named someting like
CGItemp-6074790001. It seems, on line 22, its trying to get the filehandle, but chokes on it instead. Can anyone please help
me out here??? Thanks to anyone who can try to help :)
--My source code is below--
[Code starts here]
0 #!/usr/local/bin/perl
1
2 BEGIN { $TempFile::TMPDIRECTORY = '/inetpub/tmp/' }
3
4 use strict;
5 use CGI;
6 use Fcntl qw(O_CREAT O_EXCL O_WRONLY);
7
8 use constant UPLOAD_DIR => "/inetpub/tmp";
9 use constant BUFFER_SIZE => 16384;
10 use constant MAX_FILE_SIZE => 1048576;
11 use constant MAX_DIR_SIZE => 100 * 1048576;
12 use constant MAX_OPEN_TRIES => 100;
13
14 $CGI::DISABLE_UPLOADS = 0;
15 $CGI::POST_MAX=MAX_FILE_SIZE ;
16
17 my $q = new CGI;
18
19 print "Content-type: text/plain\n\n";
20
21 my $file = $q->param("file") || print "No file specified.";
22 my $fh = $q->upload($file) || print "error";
23
24 print "File: $file\n";
[End code]
------------------------------
Date: Sun, 5 Aug 2001 13:19:15 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: CGI.pm file upload problem - Please Help!
Message-Id: <NZ2b7.4442$257.196865@ozemail.com.au>
Tut 37 is for uploading: http://savage.net.au/Perl-tutorials.html
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
------------------------------
Date: 5 Aug 2001 01:47:06 GMT
From: revjack <revjack@revjack.net>
Subject: Re: comp.infosystems.www.authoring.cgi now moderated
Message-Id: <9ki8iq$c1d$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
: I would suggest both you and Randal smarten up a bit.
Don't be Zilly, I'm pretty familiar with the oddity that is
ciwac.
Listen, if it makes you feel any better, you *do* have a
point about ciwac. Both of us are making broad proclamations
about it. I said that one ought not forge approval to it.
But hey, I did exactly that for about a month with the
dead-chicken method last year, when the approval-bot was
b0rken.
Canonical bluster just won't parse with regards to ciwac.
This isn't just my opinion, it's historicallly demonstrable.
(read: you ain't the first, lady) It's too much of an edge
case WRT orthodox usenet.
I get the idea behind ciwac, and I think you do too. Honest,
I wish you would grab one of those free email thingies and
get your approval, and be happy (and even better,
anonymous). Debating it will just skirl off into some weird
Spencer-Brown quaternary space, and I'm too old and tired
for that.
--
___________________
revjack@revjack.net
------------------------------
Date: Sun, 5 Aug 2001 03:14:59 +0100
From: James Taylor <SEE_MY_SIG@nospam.demon.co.uk>
Subject: Re: comp.infosystems.www.authoring.cgi now moderated
Message-Id: <ant050259fc4fNdQ@oakseed.demon.co.uk>
In article <3B6C8425.4E398D5A@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>
> Self-moderation was established in the cgi group to make it
> more difficult for spammers to post there. Now, without any
> warning, notice nor vote, the rule is, paraphrased, although
> Boutell remains silent:
>
> "You must register a valid email address to post here although
> this will subject you to email spamming. However, this will
> discourage spammers from spamming this group."
>
> Otherwords, no spammers here but if you want to post, you
> must agree to be victimized by spammers.
Hey, Godzilla's got a point. I wouldn't want to post to
that group without spam blocking my address. I get enough
spam as it is, and I don't have the luxury of any decent
filtering software.
Personally I find c.l.p.m. rather high traffic and c.i.w.a.c.
rather low traffic, and yet people still post CGI questions
in this group instead of using the CGI group. We should be
making it easier for people to use the CGI group, not harder.
Now although I do not condone some of the more provocative
things Godzilla has said, I do think the above snippet makes
sense. Surely nobody could disagree with the above could they?
--
James Taylor <james (at) oakseed demon co uk>
Based in Southam, Cheltenham, UK.
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: 5 Aug 2001 02:56:43 GMT
From: revjack <revjack@revjack.net>
Subject: Re: comp.infosystems.www.authoring.cgi now moderated
Message-Id: <9kiclb$dma$2@news1.Radix.Net>
Keywords: Hexapodia as the key insight
James Taylor <SEE_MY_SIG@nospam.demon.co.uk> wrote:
: Hey, Godzilla's got a point. I wouldn't want to post to
: that group without spam blocking my address.
That's a different point. Don't post with a bogus address.
Doing so only foists the problem onto someone else. Stand up
and fight, or don't complain.
--
___________________
revjack@revjack.net
------------------------------
Date: Sat, 04 Aug 2001 21:32:39 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How can I download a file and stroke a counter at the same time?
Message-Id: <3B6CA237.B0420A0F@earthlink.net>
Tony Essman wrote:
>
> Hi all,
>
> My appologies in advance if this is the wrong group
> for this post. Please redirect me if so. I searched
> usenet for a web-programming group and this seems to
> be as close as I could get. I believe it would not be
> far wrong to say most Perl programmers know or thing
> or three about web programming. This post tests my
> assumption.
>
> I'm writing a web page which offers a download. I
> want to download the file and stroke a counter on the
> server when the user clicks on the download file
> link. Nobody gets tracked -- I just want to know how
> many actual downloads were performed.
>
> I know how to download the file with href="ftp://..."
> etc., and I know how to stroke a counter on the host
> with a cgi-bin perl script. What I can't figure out
> is how to do both with just the one click on the
> download file link. Maybe that's not possible.
>
> Any help or a point in the right direction is appreciated.
This is really a CGI question, not a perl question, but:
Have the links point to filenames of the form:
http://yourhost/cgi-bin/dl_and_count.cgi/path/to/file.html
Inside the program dl_and_count.cgi, you retrieve the contents of the
PATH_INFO environment variable (which should be "path/to/file.html"),
you open, lock, increment, then close your counter, then you set binmode
on stdout, then print a CGI header appropriate for "path/to/file.html"
(in this case, it would be "Content-type: text/html", but you should
really look things up in your httpd's mimetypes file rather than try to
guess yourself), then your double newline (remember to use proper CRLFs
"\015\012", not just \n or \n\r, as those are not portable), and then
the contents of the file.
For example:
#!/usr/local/bin/perl -wT
use strict;
my $CRLF = "\015\012";
my $CRLFs = $CRLF x 2;
my $mimetypes = "/usr/local/apache/conf/mime.types";
my $counter = "/home/httpd/misc/counter.dat";
my $filename = $ENV{PATH_INFO};
my %mimetypes;
my ($path,$file) = $filename =~ m!^(.*?)/?([^/]+)$!;
if( $path !~ /valid path regex/ ) {
print "Content-type: text/plain",$CRLFs;
print "Invalid path prefix: <$path>\n";
exit;
}
if( open my $cfh, "+<", $counter ) {
eval { # try to flock, but if the OS doesn't support it,
# or if it fails to lock, ignore it.
require Fcntl;
import Fcntl qw(:flock);
flock $cfh, LOCK_EX;
};
my $old = <$cfh>;
seek $cfh, 0, 0;
print $cfh, ++$old;
truncate $cfh, length $old;
close $cfh;
} else {
# print the error to the httpd log
print STDERR "Could not open $counter for rw: $!\n";
# but don't exit, since it's not really important.
}
open( my $fh, "<", "$path/$file" ) or do {
print "Content-type: text/plain", $CRLFs;
print "File not found: <$path/$file>\n";
exit;
}
binmode STDOUT;
binmode $fh;
my $sz = -s $fh;
my ($ext) = $file =~ /([^.]*)$/
my $type = $mimetypes{$ext} || "application/unknown";
print "Content-type: ", $type, $CRLF;
print "Content-length: ", $sz, $CRLF if $sz > 0;
print $CRLF;
$sz and sysread($fh, $_, $sz) and print;
print while( sysread( $fh, $_, 4096 ) );
close $fh;
exit;
BEGIN { %mimetypes = do {
open(my $fh,"<",$mimetypes) and
map {
my ($type, @exts) = split;
map { $_ => $type } @exts
} grep { !/^\s*#/ and /\s/ } <$fh>
} }
__END__
The above code is untested.
--
I need more taglines. This one is getting old.
------------------------------
Date: 4 Aug 2001 19:01:17 -0700
From: xenite9@my-dejanews.com (Adam)
Subject: Re: Howto run traceroute-parse IP's-store in array?
Message-Id: <b67a511f.0108041801.78964ae9@posting.google.com>
Thanks!
I hope you guys get this, I've taken WAY too long to respond. I had
to look at apartments the last couple days. Both examples that were
posted worked great. And Anno, one line of code? That trims things
down significantly. I didn't think about the different data sets for
traceroute/tracert output; it was an oversight. For some reason
regular expressions have always been a weak point. I've already
started programming the next step in my project and hope to have
something turned out in the next week. Thanks a lot.
-Adam
demerphq@hotmail.com (Yves Orton) wrote in message > > Hello,
> >
> > I am trying to write a Perl script that will run traceroute (or maybe
> > mtr) and parse out the IP addresses and store them in an array.
> > Anyone know how to do this? Below is my ATTEMPT to do half of the
> > job, and I can't make it work properly. Just to point out the
> > obvious, I am not a Perl programmer, so be gentle. Please help.
>
> A sample data set would help those of us who arent on the same OS to
> help you.
> My solution is provided below, and is for NT tracert.
>
> > -----------
> > #!/usr/bin/perl -w
> >
> > use strict;
> >
> > system("/usr/sbin/traceroute www.google.com > tr.txt");
>
> I think you should read up on backticks. For instance I would do it
> this way:
>
> my $txt=`tracert www.google.com`; #backticks
>
>
> > my @array = ("tr.txt");
> >
> > for my $i(@array) {
> > open(FH, "$i");
>
> should be (if you are going to do it this way, which you shouldnt.
>
> open(FH,$i) || die "Cant open $i: $!";
>
> > while(<FH>) {
> > $_ =~ s/ /\n/g;
> > #THE ABOVE LINE DOES HALF OF THE WORK, BUT I CAN'T GET IT TO ONLY
> > #PARSE LINES BEGINNING WITH "(" AND ENDING IN ")" WHERE THE IP
> > #ADDRESSES ARE LOCATED.
> > print $_;
> > }
> > }
> > ------------
>
> This is a little strange... I dont follow your logic at all.
> >
> > MY PROJECT OUTLINE:
> <SNIP>
>
> Well here how I would pull the IPs out of the output from tracert. I
> have provided said output in the data block so you can see the idea.
> I imagine (not having seen you input) that you could replace
> (/\[([^\]]+)\]/);
> with
> (/\(([^)]+)\)/);
> if the IPs are in round brackety and not square brackets.
>
> Good luck on your project. Sounds quite ambitious.
>
> Yves
> ________________________________
> #!perl
> use strict;
> use warnings;
> my @ips;
> while (<DATA>) {
> next if !/^\s*\d+/;
> push @ips,$1 if (/\[([^\]]+)\]/);
>
> }
> print join(",",@ips)."\n";
>
> __DATA__
> Tracing route to computer.company.com [123.123.123.123]
> over a maximum of 30 hops:
> 1 <10 ms <10 ms <10 ms computer1.company.com [123.123.123.1]
> 2 <10 ms <10 ms <10 ms computer.company.com [123.123.123.123]
> Trace complete.
------------------------------
Date: Sun, 05 Aug 2001 02:43:22 GMT
From: "Billy \"Bob\" Bob" <billy_dont_try@verizon.net>
Subject: prompting and redirection with ssh
Message-Id: <qicpmtk7sa22abqdfabglrjc2n3k1o6vjh@4ax.com>
*** start doh ***
It looks like I goofed with the original post. It doesn't look like
the attachment made it.
Sigh, if only the newbies (like myself) would use alt.test
*** end doh ***
Hi,
I am trying to figure out how to "intelligently" prompt the user from
perl. I have read a great deal from this newsgroup (via
groups.google.com), the perl cookbook, and other resources. Attached
is the script that I have written based off of these readings.
It appears to work in every scenario I throw at it from the console.
Below are some examples usages:
./input.pl . file -
echo input | ./input.pl - file
echo input | ./input.pl - file /dev/tty
echo input | ./input.pl - file /dev/tty > a
./input_pl file - /dev/tty > a
However, when I try and run this last one via ssh the prompt does not
appear on the screen. It is re-directed to the file 'a'. That is,
when I:
ssh -t host input.pl file - /dev/tty > a
It does not work like I exepct. I am using ssh version:
OpenSSH_2.5.2p2, SSH protocols 1.5/2.0, OpenSSL 0x0090601f
Do you have any ideas on how I can get it to work with ssh?
#! /usr/bin/perl -w
#
# input.pl
#
# This is a program that tries to intelligently prompt the user.
#
# This program tries to "behave" whether it passed a file, -, or a tty
# device to get input from. In addition to handling files passed into
# us this program tries to handle the following situations:
#
# - pipe stdin to us
# - redirect stdin
# - redirect stdout
#
use strict;
#
# this is needed b/c we aren't using the <ARGV> magic. I don't know how
# to accomplish intelligent prompting with magic. Below is one reason
# why:
#
# ./input.pl non_existent_file -
#
# What will happen w/ <ARGV> is that "non_existent_file" is
# *automatically* skipped and "-" is *immediately* opened. This does
# not give us a chance to prompt the user when obtaining the *1st* line
# of input from them.
#
@ARGV = ('-') unless @ARGV;
while (my $FH = shift) {
my $prompt_code;
my $noinput_code;
open FH, $FH or warn "Can't open $FH: $!\n";
$prompt_code = 'print ""';
$noinput_code = 'print "No meaningful input detected.\n"';
#
# handles the case were we are getting input from a tty. However,
# output may not be going to a tty, so we should try and take care
# of that.
#
# That is to say, we must get input from the user, but our prompt will
# not goto the user (by default).
# e.g. "echo input | ./input.pl - file /dev/tty > a"
#
if (-t FH) {
if (!-t STDOUT) {
open PROMPT_TTY, "> /dev/tty" or
die "Can't open /dev/tty: $!\n";
$prompt_code = 'print PROMPT_TTY "Feed me: "';
$noinput_code =
'print PROMPT_TTY "No meaningful input detected.\n"';
} else {
$prompt_code = 'print "Feed me: "';
}
}
eval $prompt_code;
while (<FH>) {
chomp;
if (/^\s*$/) {
eval $noinput_code;
next;
}
print "You entered: $_\n";
} continue {
eval $prompt_code;
} # end getting input from a user
#
# this tries to make the ouput less "jagged" (b/c when the user
# types EOF a newline is not output)
#
if (-t FH) {
if (!-t STDOUT) {
print PROMPT_TTY "\n";
close PROMPT_TTY;
} else {
print "\n";
}
}
} # end parsing file list
------------------------------
Date: Sun, 05 Aug 2001 04:28:23 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: reading and writing arrays
Message-Id: <3B6CAF47.50102@post.rwth-aachen.de>
Nathan Randle wrote:
>I am trying to read a whole file into an array change one of the elements
>then save the whole array overwriting all the data in the file. I have used
>the code below to select which element is being changed then write over the
>file but when I run it only the element i changed is saved so there is only
>1 line in my file.
>
>Any help appreciated.
>
>open(MAP,">template.dat") or die("Coldn't open file for writing: $! \n");
>flock(MAP,2);
>
>@data = <MAP>;
>$data["(($FORM{'codtwo'}-1)*30)+$FORM{'codone'}"]="$FORM{'north'}|$FORM{'eas
>t'}|$FORM{'south'}|$FORM{'west'}|$FORM{'marks'}|";
>
This has nothing to do with your problem, but....
>
>
>print MAP "@data";
>
is not equal to print MAP @data;
When quoting an array, the elements arent's just printed as they are,
but instead they get printed with a whitespace between them. Though this
usally does not cause problems, it may under certain circumstances break
a file, for instance makefiles that rely on a certain indenting.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 5 Aug 2001 01:47:21 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: serial ports/modems and chat2.pl
Message-Id: <996976039.97466@elaine.furryape.com>
In article <9kdoe3$cup$1@penthesilea.materna.de>,
Ronan O'Connor <ronan.oconnor@materna.nl> wrote:
>
>David Efflandt <see-sig@from.invalid> wrote in message
>news:slrn9mju1a.ljg.see-sig@typhoon.xnet.com...
>> On Thu, 2 Aug 2001, Ronan O'Connor <ronan.oconnor@materna.nl> wrote:
>> > I'm looking for information on chat2.pl. Can anyone point me towards
>> > documentation.
>> > I'm planning to use chat2.pl to connect to a modem on the serial port.
>> > Anyone know of any useful modules to do this?
>>
>> What OS? Win32::SerialPort, has been ported as Device::SerialPort for
>> Unix and includes many example scripts. I have used the latter to get the
>> response from AT commands in Linux.
>>
>I'm currently working in Red Hat and NetBsd, with plans to move to Solaris
>and eventually over to Windows
>
>If anyone can point me towards docs on chat2.pl, I'd be grateful
>
chat2.pl is very outdated, and should be considered obsolete. As
the comments say
#
# This library is no longer being maintained, and is included for backward
# compatibility with Perl 4 programs which may require it.
#
# In particular, this should not be used as an example of modern Perl
# programming techniques.
#
# Suggested alternative: Socket
#
In addition, I don't think it's what you want. It's more aimed at a
socket interface (hence the suggested alternative).
In addition to the two modules suggested above, I'd also suggest
'Expect'.
------------------------------
Date: 4 Aug 2001 18:20:48 -0700
From: kenphilbrick@mindspring.com (Ken)
Subject: using eval
Message-Id: <f8b445c0.0108041720.2cbbee7a@posting.google.com>
I'm trying to use eval to execute all the code contained in a separate
file. I've tried the following:
eval "file.pl";
but, of course, that ends up trying to execute the string "file.pl" as
if it were code.
How can I make eval run the code contained in file.pl?
Thanks.
--
Ken
------------------------------
Date: Sun, 05 Aug 2001 02:47:49 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: using eval
Message-Id: <pt2b7.9752$K6.3948128@news2>
In article <f8b445c0.0108041720.2cbbee7a@posting.google.com>,
kenphilbrick@mindspring.com (Ken) writes:
> I'm trying to use eval to execute all the code contained in a separate
> file. I've tried the following:
>
> eval "file.pl";
>
> but, of course, that ends up trying to execute the string "file.pl" as
> if it were code.
>
> How can I make eval run the code contained in file.pl?
eval {
require "file.pl";
};
or
open(F, "file.pl") || die;
{
local $/;
$a=<F>;
}
eval "$a";
or, if you don't really need eval...
do "file.pl";
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
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 1445
***************************************