[9033] in Perl-Users-Digest
Perl-Users Digest, Issue: 2651 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 20 18:07:31 1998
Date: Wed, 20 May 98 15:00:52 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 20 May 1998 Volume: 8 Number: 2651
Today's topics:
Re: Can Perl call k shell scripts? (Jason Gloudon)
Re: dbm and perl (Jason Gloudon)
Re: Flushing STDIN before read? <tchrist@mox.perl.com>
Re: Inter-process file arbitration? <jgoldberg@dial-but-dont-spam.pipex.com>
Re: Inter-process file arbitration? <jgoldberg@dial-but-dont-spam.pipex.com>
Re: Perl 5.0 map operator <dformosa@st.nepean.uws.edu.au>
Re: Perl forking <tchrist@mox.perl.com>
Re: Perl terminology <tchrist@mox.perl.com>
Re: perl variables <jeffyjo-isom@worldnet.att.net>
Re: Perl/Wall lingo question (Josh Kortbein)
Re: Problem de-referencing a reference to a typeglob st <tchrist@mox.perl.com>
Re: reading (lots of) files in perl ? <aqumsieh@matrox.com>
Re: Running Perl on Windows <igor.k@usa.net>
Re: Running Perl on Windows (Alan Meyer)
Re: sending regex matches to a separate file <mahmed@dkl.com>
Re: Software vendor liability [Was: Does Perl have a ID (Stuart McDow)
Re: Software vendor liability [Was: Does Perl have a ID <tchrist@mox.perl.com>
Sourcing Unix environment file? <thuyn@nortel.com>
Re: string comparisons (Craig Berry)
Re: translate A-Z to 1-26 <aqumsieh@matrox.com>
trying to filter with ne GoYankees98@my-dejanews.com
Re: What is wrong with this FileHandle code? <tchrist@mox.perl.com>
Why does "each" not go thru entire hash?? <tturton@cowboys.anet-dfw.com>
win32 ftp'put problem with ftp.pl <etiquet@sv.vtcom.fr>
Year2000 compliant? <wgong@hpprsd1.sc.hp.com>
Re: Year2000 compliant? (Craig Berry)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 20 May 1998 21:09:03 GMT
From: jgloudon@hyssop.bbn.com.bbn.com (Jason Gloudon)
Subject: Re: Can Perl call k shell scripts?
Message-Id: <PDH81.26$152.393955@cam-news-reader1.bbnplanet.com>
IoanJ@my-dejanews.com <IoanJ@my-dejanews.com> wrote:
.
.
>if ( $input eq "y" ){
> `korn`;
>}
In order for your shell to give you a prompt etc.. It has to think it is
being run interactively. Shells normally start in interactive mode if their
standard input and output are terminals. `korn` starts your shell with its
output redirected, so it doesn't startup in interactive mode.
Try system "korn" as this does not redirect standard input and output.
Jason Gloudon
------------------------------
Date: Wed, 20 May 1998 21:34:06 GMT
From: jgloudon@hyssop.bbn.com.bbn.com (Jason Gloudon)
Subject: Re: dbm and perl
Message-Id: <i%H81.27$152.408032@cam-news-reader1.bbnplanet.com>
Robert Stagner <rstagner@atcreation.com> wrote:
>I'm interested in using Perl's Database functionality (specifically
>'dbmopen' and 'dbmclose') to read from an associative array. The array
>will contain fields associated with restaurants and other catering
If you have a system with perldoc, try looking at
perldoc AnyDBM_File and perldoc dbmopen, The first one references other
pieces of documentation.
--
Jason Gloudon
------------------------------
Date: 20 May 1998 21:34:15 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Flushing STDIN before read?
Message-Id: <6jvi8n$r4h$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
psmith@baynetworks.com writes:
:OK, so I have this important question I want to ask the user. I'm
:reading from STDIN. I want to flush any typeahead he/she may have
:entered, to avoid possible incorrect responses.
>From the trn.c source, under eat_typeahead()
--tom
# ifdef I_SGTTY
ioctl(_tty_ch,TIOCSETP,&_tty);
# else
# ifdef I_TERMIO
ioctl(_tty_ch,TCSETAW,&_tty);
# else
# ifdef I_TERMIOS
tcsetattr(_tty_ch,TCSAFLUSH,&_tty);
# else
?????????
# endif
# endif
# endif
#endif
--
"Yes, you can think of almost everything as a function, but this may upset
your wife." --Larry Wall
------------------------------
Date: Wed, 20 May 1998 22:37:46 +0100
From: "Jeremy Goldberg" <jgoldberg@dial-but-dont-spam.pipex.com>
Subject: Re: Inter-process file arbitration?
Message-Id: <6jvigo$cj8$1@plug.news.pipex.net>
>>>open(FD, ">blah") or die "$$ open: $!";
>>>flock(FD, LOCK_EX);
>>
>>But the open will fail if another process is writing to it!
>
>Won't. Locking is advisory.
OK... I'm missing something elementary here. Someone has the file opened for
writing, i.e. exclusively, and I do:
open(FD, ">blah") or die "$$ open: $!";
Why won't it fail? I'm not talking about the flock(), I'm talking about the
open() that comes first.
------------------------------
Date: Wed, 20 May 1998 22:39:50 +0100
From: "Jeremy Goldberg" <jgoldberg@dial-but-dont-spam.pipex.com>
Subject: Re: Inter-process file arbitration?
Message-Id: <6jvikj$cte$1@plug.news.pipex.net>
>In comp.lang.perl.misc, "Jeremy Goldberg"
>:But the open will fail if another process is writing to it!
>
>Stop lying. The only system that would do that would be one designed to
>make multitasking idiocruddyotic. Sounds like Martian programming,
>a queer notion at best, and evil and broken one in all probability.
See the reply to M. Dominus - I'm getting really confused here, perhaps it's
a conspiracy to drive me up the wall?
------------------------------
Date: 20 May 1998 20:44:18 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: Perl 5.0 map operator
Message-Id: <895697058.205487@cabal>
In <01bd83d6$64787da0$e8dda487@N440-E39.att.dom> "Ron Sullivan" <baserad2@attmail.com> writes:
[...]
>@nums = ( 60 .. 62 );
>$tmp = map { z,$_ } @nums;
>print "$tmp\n";
>According to the Perl 5.0 man page, the block inside the curly braces is
>evaluated in LIST context with $_ set internally to
>each element of @nums in succession and returns a list.
However map is called in a scalar context, so it returns a scalar.
The value of this scalar apparse to be undocumented, this seems to be a
bug in the docs.
--
I'm a perl programer; if you need perl programing, hire me.
Please excuse my spelling as I suffer from agraphia; see the url. Support NoCeM
http://www.cit.nepean.uws.edu.au/~dformosa/Spelling.html http://www.cm.org/
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: 20 May 1998 21:41:52 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl forking
Message-Id: <6jvin0$r4h$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
beatle@arches.uga.edu (Benjamin Dixon) writes:
:Could someone please explain to me how I can start two processes such that
:they run simultaneously. What I am trying to do is make mp3s from my CD
:collection. To automate this a bit, I wrote a simple perl script to create
:the directories and encode the mp3s, rip the CDs, etc. But as is, it first
:rips the CD, then encodes as mp3. What I would like for it to do is rip
:the first song, then begin ripping the second song while at the same time
:mp3ing the first song. I have two system calls to dagrab (cd ripper) and
:8hz (mp3 ripper). I tried to fork the two but with no such luck. I've
:looked in the faq and in "Learning Perl" as well as
:the Perl man pages and reference guide but I haven't found a good
:explaination of what I want anywhere. As I understand it, a call to system
:is the same as a call to fork and exec? Any help or pointers to help would
:be greatly appreciated.
[more Perl Cookbook excerpts]
Imagine that you're nestled deep inside a protective firewall.
Somewhere in the outside world is a server that you'd like access to,
but only processes on the firewall can reach it. You don't want to
login to the firewall machine each time to access that service.
For example, this might arise if your company's ISP provided news-reading
service that seems to come from your main firewall machine, but rejects
any NNTP connections from any other address. As the administrator
of the firewall, you don't want to have dozens of people logging on
to it. But you would like to let them read and post news from their
own workstations.
The following program, I<fwdport>, solves this problem in a generic
fashion. You may run as many of these as you like, one per outside
service. Sitting on the firewall, it has the ability to talk to both
worlds. When someone wants to access the outside service, they contact
this proxy, which on their behalf connects to the external service.
To that outside service, the connection is coming from your firewall,
so it lets it in. Then your proxy forks off twin processes, one doing
nothing but reading data from the external server and writing that data
back to the internal client, the other doing nothing but reading data from
the internal client and writing that data back to the external server.
For example, you might invoke it this way:
$ fwdport -s nntp -l fw.oursite.com -r news.bigorg.com
That means that the program will act as the server for the NNTP
service, listening for local connections on the NNTP port on the host
C<fw.oursite.com>. When one comes in, it contacts C<news.bigorg.com> (on
the same port), and then ferries data between the remote server and local
client.
Here's another example:
$ fwdport -l myname:9191 -r news.bigorg.com:nntp
This time we listen for local connections on port 9191 of the host I<myname>,
and patch those connecting clients to the remote server C<news.bigord.com>
on its NNTP port.
In a way, I<fwdport> acts as both a server and a client. It's a
server from the perspective of inside the firewall and a client from
the perspective of the remote server outside. The program is a good
summary example for this chapter, because it demonstrates just about
everything we've covered here. It has server activity, client activity,
collecting dying children, forking and process management, and a good
bit more thrown in.
#!/usr/bin/perl -w
# fwdport -- act as proxy forwarder for dedicated services
use strict; # require declarations
use Getopt::Long; # for option processing
use Net::hostent; # by-name interface for host info
use IO::Socket; # for creating server and client sockets
use POSIX ":sys_wait_h"; # for reaping our dead children
my (
%Children, # hash of outstanding child processes
$REMOTE, # whom we connect to on the outside
$LOCAL, # where we listen to on the inside
$SERVICE, # our service name or port number
$proxy_server, # the socket we accept() from
$ME, # basename of this program
);
($ME = $0) =~ s,.*/,,; # retain just basename of script name
check_args(); # processing switches
start_proxy(); # launch our own server
service_clients(); # wait for incoming
die "NOT REACHED"; # you can't get here from there
# process command line switches using the extended
# version of the getopts library.
sub check_args {
GetOptions(
"remote=s" => \$REMOTE,
"local=s" => \$LOCAL,
"service=s" => \$SERVICE,
) or die <<EOUSAGE;
usage: $0 [ --remote host ] [ --local interface ] [ --service service ]
EOUSAGE
die "Need remote" unless $REMOTE;
die "Need local or service" unless $LOCAL || $SERVICE;
}
# begin our server
sub start_proxy {
my @proxy_server_config = (
Proto => 'tcp',
Reuse => 1,
Listen => SOMAXCONN,
);
push @proxy_server_config, LocalPort => $SERVICE if $SERVICE;
push @proxy_server_config, LocalAddr => $LOCAL if $LOCAL;
$proxy_server = IO::Socket::INET->new(@proxy_server_config)
|| die "can't create proxy server: $@";
print "[Proxy server on ", ($LOCAL || $SERVICE), " initialized.]\n";
}
sub service_clients {
my (
$local_client, # someone internal wanting out
$lc_info, # local client's name/port information
$remote_server, # the socket for escaping out
@rs_config, # temp array for remote socket options
$rs_info, # remote server's name/port information
$kidpid, # spawned child for each connection
);
$SIG{CHLD} = \&REAPER; # harvest the moribund
accepting();
# an accepted connection here means someone inside wants out
while ($local_client = $proxy_server->accept()) {
$lc_info = peerinfo($local_client);
set_state("servicing local $lc_info");
printf "[Connect from $lc_info]\n";
@rs_config = (
Proto => 'tcp',
PeerAddr => $REMOTE,
);
push(@rs_config, PeerPort => $SERVICE) if $SERVICE;
print "[Connecting to $REMOTE...";
set_state("connecting to $REMOTE"); # see below
$remote_server = IO::Socket::INET->new(@rs_config)
|| die "remote server: $@";
print "done]\n";
$rs_info = peerinfo($remote_server);
set_state("connected to $rs_info");
$kidpid = fork();
die "Cannot fork" unless defined $kidpid;
if ($kidpid) {
$Children{$kidpid} = time(); # remember his start time
close $remote_server; # no use to master
close $local_client; # likewise
next; # go get another client
}
# at this point, we are the forked child process dedicated
# to the incoming client. but we want a twin to make i/o
# easier.
close $proxy_server; # no use to slave
$kidpid = fork();
die "Cannot fork" unless defined $kidpid;
# now each twin sits around and ferries lines of data
# see how simple the algorithm is when you can have
# multiple threads of control?
# fork's parent; master's child
if ($kidpid) {
set_state("$rs_info --> $lc_info");
select($local_client); $| = 1;
print while <$remote_server>;
kill('TERM', $kidpid); # kill my twin cause we're done
}
# fork's child; master's grandchild
else {
set_state("$rs_info <-- $lc_info");
select($remote_server); $| = 1;
print while <$local_client>;
kill('TERM', getppid()); # kill my twin cause we're done
}
exit; # whoever's still alive bites it
} continue {
accepting();
}
}
# helper function to produce a nice string in the form HOST:PORT
sub peerinfo {
my $sock = shift;
my $hostinfo = gethostbyaddr($sock->peeraddr);
return sprintf("%s:%s",
$hostinfo->name || $sock->peerhost,
$sock->peerport);
}
# reset our $0, which on some systems make "ps" report
# something interesting: the string we set $0 to!
sub set_state { $0 = "$ME [@_]" }
# helper function to call set_state
sub accepting {
set_state("accepting proxy for " . ($REMOTE || $SERVICE));
}
# somebody just died. keep harvesting the dead until
# we run out of them. check how long they ran.
sub REAPER {
my $child;
my $start;
while (($child = waitpid(-1,WNOHANG)) > 0) {
if ($start = $Children{$child}) {
my $runtime = time() - $start;
printf "Child $child ran %dm%ss\n",
$runtime / 60, $runtime % 60;
delete $Children{$child};
} else {
print "Bizarre kid $child exited $?\n";
}
}
# If I had to choose between System V and 4.2, I'd resign. --Peter Honeyman
$SIG{CHLD} = \&REAPER;
};
--
"Those who do not understand Unix are condemned to reinvent it, poorly."
--Henry Spencer
------------------------------
Date: 20 May 1998 21:17:23 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl terminology
Message-Id: <6jvh93$ol0$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Ala Qumsieh <aqumsieh@matrox.com> writes:
:What I liked most about it is the abundance of examples, something the
:Camel Book lacks.
I don't see why people keep saying this. I see zillions of examples
in the Camel. In fact, it's hard to open to a page without
indented code examples.
:Unfortunately though, I have discovered WAY too many
:mistakes in the example code they present.
Yup.
:But, overall, I think it's a good
:reference.
I guess I'm confused about what a "reference book" is.
Are we talking about Perl 5 Interactive or the Perl 5 How-to?
Both are better in the 2nd than first editions. Both have
some of the most terrible layout and typesetting known to man.
The former is better at being technically correct than the latter.
--tom
--
Fancy algorithms are slow when n is small, and n is usually small. --Rob Pike
------------------------------
Date: Wed, 20 May 1998 11:17:53 -1000
From: Jeff & Rebecca Jo Isom <jeffyjo-isom@worldnet.att.net>
Subject: Re: perl variables
Message-Id: <6jvh3c$kin@bgtnsc03.worldnet.att.net>
Mike Stok wrote:
> In article <6jv9e8$23t@bgtnsc02.worldnet.att.net>,
> Jeff & Rebecca Jo Isom <jeffyjo-isom@worldnet.att.net> wrote:
> >Is there a way to check the contents of a variable to see if it contains
> >a specific character?
> >
> >For example if I have a variable from a form that stores an email
> >address and I want to make sure the variable contains a @. How would I
> >accomplish this?
>
> One way to do it is to say
>
> if (index ($var, '@') >= $[) {
> ...
> }
This actually needs to be
if (index ($var, '@') <= $[) {
...
}
to work right
Jeff Isom
------------------------------
Date: 20 May 1998 21:15:10 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: Perl/Wall lingo question
Message-Id: <6jvh4u$qt5$1@news.iastate.edu>
Stephen O. Lidie (lusol@turkey.cc.Lehigh.EDU) wrote:
: Ken Fox (kfox@pt0204.pto.ford.com) wrote:
: : jdporter@min.net (John Porter) writes:
: : > kfox@pt0204.pto.ford.com (Ken Fox) wrote:
: : > > Anyways, the math notation is useless in computer science (unless the
: : > > problem domain of the program you're writing is mathematics... ;)
: : >
: : > I don't think I'd agree with that. Computer science is built on
: : > mathematics.
: : Some people seem to think so anyways. ;) When was the last time
: : you formally proved the correctness of a program? Now when was the
: : last time you built an outline of a program? IMHO, computer science
: : (except for algorithm design and analysis) is much more closely
: : related to writing (i.e. literature).
: Hmm. A computer nerd by trade but a biologist by degree, I've always
: held this hierarchy, in Makefile terminology:
: biology: chemistry
: chemistry: physics
: physics: mathematics
: e.g., the world view is described by mathematics.
: Where to classify CS or linguistics? Ultimately it's a biological
: function. I think.
Some interesting tidbits which don't help at all to clarify this question:
The AMA classifies "computer science" as a large subset of the "normal"
math literature.
At my university, a class called "theory of computing" is cross-listed
as computer science and linguistics (though I'd imagine it probably
scares the crap out of the linguistics majors). Similar material is
covered in graduate-level math logic classes, but not in undergrad math.
Linguistics is often classified as a social science, though at my
university the linguistics department is a bastard child, most of its
classes actually cross-listed classes from other departments.
So... if you care at all what universities think about the matter... :)
Josh
____________________________________________________________________
"Writing is like prostitution. First you do it for the love of it,
then you do it for a few friends, and finally you do it for money."
- Moliere
------------------------------
Date: 20 May 1998 21:45:44 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Problem de-referencing a reference to a typeglob stored in a hash
Message-Id: <6jviu8$r4h$4@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, in an spamproofed address now revealed to the
world, ameyer@ix.netcom.com (Alan Meyer) writes:
:Why should the expression <$x{FH}> behave differently
:from <$x> ???
I *know* I just explained this. Please go back to the FMTEYEWTK on
Indirect FileHandles posting form a few days ago.
--tom, who hates people shoving their spam problems under his carpet
--
What about WRITING it first and rationalizing it afterwords? :-)
--Larry Wall in <8162@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Wed, 20 May 1998 16:21:22 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: reading (lots of) files in perl ?
Message-Id: <35633B42.9AF778AE@matrox.com>
scottse@my-dejanews.com wrote:Hmm.. let's see ... you seem to be opening two
files, reading the contents, adding some value in between, then printing that on
the screen.
If I am correct, then you can try something like this:
$primary_so= 12345;
@question_html_array = ('question_header.html','question_body1.html');
foreach $file_name (@question_html_array) {
open (FILE, '/opt/local/http/ifsdoc-cgi-bin/html/' . $file_name) or die
"Can't open $file_name: $!";
$file_name =~ s/\.html$//;
@{$file_name} = <FILE>;
}
$question_string = join "", @question_header,$primary_so,@question_body1;
That might not be the cleanest way to do it. But it certainly is cleanER ;-)
I'll try and point out some of the mistakes your code has:
> -----
> #!/usr/local/bin/perl
ALWAYS use the -w switch! PLEASE!
> $primary_so = 12345;
>
> @question_html_array = ('question_header.html','question_body1.html');
>
> %question_html_file_array =
> ("question_header.html","question_header","question_body1.html","question_bod
> y1");
>
> $question_html_files = @question_html_array;
Woo .. I am seeing doubles by now! ;-)
> for ($question_html_count = 0; $question_html_count != $question_html_files;
> $question_html_count++) {
That works fine, but the easier, more Perlish way to do it is like I did using a
foreach statement.
> $FILE_HANDLE =
> ($question_html_file_array{$question_html_array[$question_html_count]});
> $INPUT_FILE = ("/opt/local/http/ifsdoc-cgi-bin/html/" .
> $question_html_array[$question_html_count]);
> open (FILE_HANDLE,INPUT_FILE) || die ("Error reading : $!;");
Hmmm... is this FILE_HANDLE supposed to be the same as $FILE_HANDLE?This is
getting confusing. Maybe you would want to stick to the convention that file
handles are capitalized whereas variables aren't. $FILE_HANDLE is a variable
that contains a string which is the name of a file handle.
Also, you CAN do here:
@{$FILE_HANDLE} = <$FILE_HANDLE}
(Check man perlref).
> };
>
> @question_header = <question_header>; # is there any way to do this in
> @question_body1 = <question_body1>; # the for loop ?
>
> $question_string = join (@question_header,$primary_so,@question_body1);
Hmmm.. take a closer look at the join() operator. You are missing something.
> print $question_string;
>
> -----
> What I'm trying to do is read a large number of files and then create a final
> variable from the contents of the files joined with some data from another
> source.
>
> I'm not a programmer by any means, and I'm hoping that someone can give me a
> hint as to how to the above a bit more efficiently....
>
> Thanks
> Scott
Hope that was helpful.
--
Ala Qumsieh | No .. not just another
ASIC Design Engineer | Perl Hacker!!!!!
Matrox Graphics Inc. |
Montreal, Quebec | (Not yet!)
------------------------------
Date: Wed, 20 May 1998 13:58:12 -0700
From: "Igor Krivokon" <igor.k@usa.net>
Subject: Re: Running Perl on Windows
Message-Id: <6jvga1$114$1@news.ncal.verio.com>
Alan Meyer wrote in message <6jvfa5$f89@sjx-ixn5.ix.netcom.com>...
>One simple, dumb, technique that has always worked for me is to make a
>batch file in parallel with the perl script.
>
>If the script is "foo.pl", you can make a file named "foo.bat" with
>the following contents:
>
> {perlpath}\perl {foopath}\foo.pl $1 $2 $3 $4 $5 $6 $7 $8 $9
>
>Plain "foo" runs the program, passing it however many command line
arguments
>there are up to 9 of them.
should be %1 %2 %3 %4 %5 %6 %7 %8 %9
instead of $1 $2 $3 $4 $5 $6 $7 $8 $9
(just typo, probably)
Regards,
Igor Krivokon
<igor.k@usa.net>
------------------------------
Date: 20 May 1998 21:34:04 GMT
From: ameyer@NoSPAMix.netcom.com (Alan Meyer)
Subject: Re: Running Perl on Windows
Message-Id: <6jvi8c$f89@sjx-ixn5.ix.netcom.com>
In article <6jvga1$114$1@news.ncal.verio.com>, igor.k@usa.net wrote...
>should be %1 %2 %3 %4 %5 %6 %7 %8 %9
>instead of $1 $2 $3 $4 $5 $6 $7 $8 $9
>(just typo, probably)
>
>Igor Krivokon
><igor.k@usa.net>
Yes! Thank you.
--
Alan Meyer
AM Systems, Inc
Randallstown, MD
ameyer@NoSPAMix.netcom.com
(Please remove NoSPAM from address for email)
------------------------------
Date: Wed, 20 May 1998 17:06:46 -0400
From: Mahmoud Ahmed <mahmed@dkl.com>
To: michael@datahost.com
Subject: Re: sending regex matches to a separate file
Message-Id: <356345E6.BA5D182E@dkl.com>
Hi Micheal,
You got it, but don't use array just use variable and also save it on
output file.
Here is your modified script... IT WORKS.
#!/usr/local/bin/perl
foreach (@ARGV) {
open (INFILE,"$_") || die ("Can't Open $_\n");
open (OUTFILE,">list.txt") || die ("Can't Open list.txt\n");
while ($text=<INFILE>) {
print "$text\n";
while ($text=~s/(http:\/\/.*?)">/$1/) {
print OUTFILE "$1\n"; # Store output file
}
}
close (INFILE);
close (OUTFILE);
}
Michael Stearns wrote:
> Hello:
>
> I would like to open a bunch of text files in a directory, get all urls
> and put them in another file, in a list.
>
> How do I write a regex that takes each matching item and sticks it in a
> separated variable (or maybe I should be putting them in an array?)
>
> Thanks for any suggestions. Here's what I currently have below
>
> #!/usr/local/bin/perl
>
> foreach (@ARGV) {
>
> open (INFILE,"$_") || die ("Can't Open $_\n");
> @text=<INFILE>;
> $text=join("",@text);
> print "$text\n";
>
> while ($text=~s/(http:\/\/.*?)">/$1/) {
>
> $text2=$text2.$1\n;
>
>
> }
> close (INFILE);
> open (OUTFILE,">list.txt") || die ("Can't Open $_\n");
> print OUTFILE ($text2);
> }
--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Mahmoud Ahmed
Data Kinetics Limited
http://www.dkl.com
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
------------------------------
Date: 20 May 1998 21:07:46 GMT
From: smcdow@arlut.utexas.edu (Stuart McDow)
Subject: Re: Software vendor liability [Was: Does Perl have a IDE?]
Message-Id: <6jvgn2$t1f$1@ns1.arlut.utexas.edu>
kfox@pt0204.pto.ford.com (Ken Fox) writes:
>
> The ones who produce dangerous crap wouldn't be able to continue to
> make money simply by having a fabulous marketing team.
Except for the "dangerous" part (then again, maybe not), this sounds
like a particular computer company that has a near-monopoly in the x86
platform market.
> Other vendors might have to slow down the rate of "innovation," but
> then we'd have more reliable software with fewer features. Hmm, not
> a bad idea.
Maybe someone should tell that to the computer company that has a
near-monopoly in the x86 platform market. They'd rather "innovate"
than make their current product more reliable.
IMHASO, of course.
> The really sad thing about software liability is that Ford, which is
> a car company, can be sued for defective software, but Microsoft,
> which is a software company, can't.
Sad indeed.
--
Stuart McDow Applied Research Laboratories
smcdow@arlut.utexas.edu The University of Texas at Austin
"Look for beauty in roughness, unpolishedness"
------------------------------
Date: 20 May 1998 21:19:19 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Software vendor liability [Was: Does Perl have a IDE?]
Message-Id: <6jvhcn$ol0$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
smcdow@arlut.utexas.edu (Stuart McDow) writes:
:They'd rather "innovate"
:than make their current product more reliable.
You have a funny way of spelling copy.
--tom
--
Basically, avoid comments. If your code needs a comment to be understood,
it would be better to rewrite it so it's easier to understand. --Rob Pike
------------------------------
Date: Wed, 20 May 1998 16:06:30 -0500
From: Thuy Nguyen <thuyn@nortel.com>
Subject: Sourcing Unix environment file?
Message-Id: <356345D6.7705@nortel.com>
Hi,
I am trying to source in a Unix environment file from a perl script, but
was unable to do so.
Here is the problem:
at the Unix prompt, one can type
$ . /etc/navenv.d/DBSEnv
and it would read the DBSEnv file and set the appropriate environment
parameters.
I have tried using the system and exec commands, but none of it works.
e.g
$cmd = ". /etc/navenv.d/DBSEnv";
system ($cmd);
I have tried to overwrite the special metacharater "." by preceding the
"." with the "\", and it still did not work.
Have anyone run into this problem before? And if you have, how would
you resolve it? Any suggestions will be appreciated. Thank you.
Regards,
Thuy
------------------------------
Date: 20 May 1998 20:56:45 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: string comparisons
Message-Id: <6jvg2d$spn$3@marina.cinenet.net>
armitage21@my-dejanews.com wrote:
: Can someone help me out and tell me how I should go about comparing strings
: using PERL? Thanks!
Yes! In fact, the good folks who brought us Perl also included a really
staggering amount of documentation about Perl, bundled right in with it in
any valid distribution. On most systems, you should be able to do
perldoc perlop
("show Perl documentation about Perl operators") and find out all about
string comparisons along with many other useful operators.
Still better, get _Learning Perl_ (the so-called "Llama Book" from
O'Reilly) and learn from that fine text.
Best of luck!
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Wed, 20 May 1998 16:36:41 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: translate A-Z to 1-26
Message-Id: <35633ED9.48A655D6@matrox.com>
Shaun Sides wrote:
> I realize that, now, and I formally apologize to the 'group for posting
> something so ... stupid. In penance, I will now commence to read the
> tr/// entry in the camel book no fewer than 5 times a day for a week.
> (I feel doubly stupid because I own the camel book but still did that)
Maybe you should do that while upside down to pile all the information in
your brain 8-)
> > Nice try though ;-)
>
> ::sigh:: Guess I'll thank all of you for not being very hard on me.
No need to apologize. I made the same mistake (but I didn't tell anyone ;-\
)
Trust me, you won't learn unless you make mistakes .. and plenty of them :)
--
Ala Qumsieh | No .. not just another
ASIC Design Engineer | Perl Hacker!!!!!
Matrox Graphics Inc. |
Montreal, Quebec | (Not yet!)
------------------------------
Date: Wed, 20 May 1998 21:14:07 GMT
From: GoYankees98@my-dejanews.com
Subject: trying to filter with ne
Message-Id: <6jvh2u$l2r$1@nnrp1.dejanews.com>
Hello,
I have a small problem I haven't been able to figure out. I have an HTML form
that I am reading content in to STDIN. As I parse through the submitted
values, I want to put them into a variable for later use. Except, I want to
filter some out.
Here is what I have:
## Process STDIN which is placed into $bigcontent
## You've all seen this before...
@cont = split(/&/, $bigcontent);
foreach $cont (@cont) {
($name, $value) = split(/=/, $cont);
$value =~ tr/+/ /;
$value =~ s/%0D//eg;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$input{$name} = $value;
## This is where my trouble is. I want to put most,
## but not all the submitted info a variable I can then
## PRINT into mail. All the hidden variables I don't
## want begin with 'nm'. I want to filter them out before
## I put the rest into $tvar. So I made two trys
##This is attempt one, didn't work
#if ($input{$name} ne "nm".*)
##This is attempt two, didn't work either
if ($input{$name} ne "nmresultpage" || $input{$name} ne "nmsubject" ||
$input{$name} ne "nmto" || )
## This is where I want my content to go
{
$tvar= "\n$tvar $name: $value\n\n";
}
}
Also, for some reason, there are several line returns printing at the top of
$tvar, but I can't figure out where they're coming from.
Any comments or suggestions greatly appreciated.
Regards,
Jay
### If you were behind this firewall, you'd be using Deja too...
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 20 May 1998 21:39:12 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: What is wrong with this FileHandle code?
Message-Id: <6jvii0$r4h$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
jim.michael@gecm.com writes:
:> $fh = new FileHandle;
:> if ($fh->open("f1.txt")) {
:> print <$fh>;
:> undef $fh;
:> }
:
:OK, adding the parens worked. Neither example (perldoc or Camel) used
:the parens.
Yup, doc bug. Method calls always need parens for their argument.
But you really don't want to use the silly module anyway. Why suck
in 5,000 lines of code when the open function *works perfectly fine*,
and about a zillion times faster, too.
--tom
--
"What is the sound of Perl? Is it not the sound of a wall that
people have stopped banging their heads against?"
--Larry Wall in <1992Aug26.184221.29627@netlabs.com>
------------------------------
Date: Wed, 20 May 1998 16:09:56 -0500
From: Tom Turton <tturton@cowboys.anet-dfw.com>
Subject: Why does "each" not go thru entire hash??
Message-Id: <356346A3.229D7A85@cowboys.anet-dfw.com>
I am seeing some bizarre behavior while trying to use a while/each on a
hash. It appears to jump into the middle/end of the hash the first time
through.
Here is a segment of what I have:
%runway = ("DFW18R", 0, "DFW18L", 1, "DFW17R", 2, "DFW17C", 3, "DFW17L",
4, "DFW13R", 5, "DFW35C", 6, "DFW35R", 7 , "DFW35L", 8, "DFW36L", 9,
"DFW36R", 10, "DFW31R", 11, "DFW13L", 12, "DFW31L", 13);
.
.
for ($rwi=0; $rwi<14; $rwi++) {
while( ($m,$n) = each(%runway)){
if ($n == $rwi) {
print OUTFILE "\$rwi = $rwi, \$n = $n\n";
}
}
}
If I run the above snippet of code in a small test program, it operates
as I would expect. In this case, the hash seems to be initiated in the
following index (value) order:
13,12,8,4,9,1,11,5,2,7,0,3,6,10
When I run it in my main program, the first time through ($rwi = 0), it
appears to check starting with 'values' 3,6,10 then goes on to index
$rwi=1 and loop starting at hash value '13' down until it matches '1';
$rwi=2 starting again with hash value '13' down until it matches '2',
etc.
Is there anything I might be doing which would cause this type of
behavior?
Thank you.
---Tom Turton
------------------------------
Date: Wed, 20 May 1998 23:27:46 +0200
From: "Eric TIQUET" <etiquet@sv.vtcom.fr>
Subject: win32 ftp'put problem with ftp.pl
Message-Id: <6jvhrd$jc6@news.vtcom.fr>
I had a bug while try to use the ftp'put function of the ftp.pl script,
while trying to port the mirror.pl script.
When the file to transfert (put) is less than 4096 bytes the function does
not
transfert anything.
I try :
$_=select(NS);
$|=1;
select($_);
to specify to sell directly the stream but it is worse,
the file at the end is not really the same.
Someone has got an idea or suggestions ...
Thanks
Eric Tiquet
ps: no problem with ftp'get
------------------------------
Date: Wed, 20 May 1998 14:04:32 -0700
From: Wen Gong <wgong@hpprsd1.sc.hp.com>
Subject: Year2000 compliant?
Message-Id: <35634560.552B@hpprsd1.sc.hp.com>
Hello,
Does anyone know if Perl 4.0+ is Year2000 compliant?
Thanks.
Wen
--
Wen Gong / / wen_gong@hp.com
Mailstop 51U IB /---/--\
Hewlett-Packard, Inc. / /| |
5301 Stevens Creek Blvd. / / |--/ Tel: (408) 345-8484
Santa Clara, CA 95052-8059 / / | Fax: (408) 345-8531
|
------------------------------
Date: 20 May 1998 21:25:26 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Year2000 compliant?
Message-Id: <6jvho6$spn$4@marina.cinenet.net>
Wen Gong (wgong@hpprsd1.sc.hp.com) wrote:
: Does anyone know if Perl 4.0+ is Year2000 compliant?
Oh, god, here we go again.
First, see Deja News for endless discussion of this topic.
Second, don't use Perl 4 for anything at all; it's got serious security
and stability problems. Stick with Perl 5, and indeed 5.004, the current,
stable, secure, *good* version.
Third, Perl is Y2K compliant to the exact same degree a pencil is. You
can write today's date as 5/20/98 with a pencil; you can write Y2K bugs in
Perl. The language itself is Y2K neutral, though it provides the proper
tools to build Y2K-compliant apps.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 2651
**************************************