[6894] in Perl-Users-Digest
Perl-Users Digest, Issue: 519 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 23 00:07:22 1997
Date: Thu, 22 May 97 21:00:22 -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 Thu, 22 May 1997 Volume: 8 Number: 519
Today's topics:
Re: $ARGV not working? (Nathan V. Patwardhan)
\b refuses to work properly zingbust@montana.com
Re: Baffled <nelson@cae.ca>
Re: Cross Platform CGI Programmer Needed (Matthew D. Healy)
err compiling IO module <otisg@panther.middlebury.edu>
getting started... <marien@goodnet.com>
getting started.. <marien@goodnet.com>
Re: help - grep lines between two line patterns (Bek Oberin)
Re: How to process logfiles with begin/end brackets? (Tad McClellan)
Installing a Module in local directory (Brieweb)
Re: Making a pool, but one man = one vote (Bill)
Re: Making a pool, but one man = one vote (Kent Perrier)
Re: Members Only Section? (Kent Perrier)
Re: my(), foreach, and perl 5.004 (Abigail)
Re: Need help with getting timezone from date (Clay Irving)
pattern matching/counting occurrences of text item <cmt@ucla.edu>
questions about chop <Scott@wwide.com>
Re: regexp problem (Tad McClellan)
RegExp tutorial suggestions? <jsoloff@psu.edu>
Some PERL questions... <doyle@teleport.com>
Re: Split function (Edward Jajko (The Nekomancer))
Re: split'\|'; except when preceded by '/' (Abigail)
Re: split'\|'; except when preceded by '/' <chaimf@cris.com>
Re: Why doesn't this simple script work? (Bek Oberin)
Re: yyyymmdd from localtime? (Dennis Marti)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 May 1997 01:00:10 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: $ARGV not working?
Message-Id: <5m2q6q$mc1@fridge-nf0.shore.net>
Craig M. Votava (craig@lucent.com) wrote:
: So the following program (if executed with a '*' argument in a directory
: that has ascii files) should print out all of the different file names,
: one for each line in the file, right? On my system it only prints the
: filename of the last file, for every line in every file. Please help!
perl -e 'while (<>) { print "In file: ",$ARGV,"\n";}' <filenames>
seems to do what you're describing.
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: Thu, 22 May 1997 18:41:09 -0600
From: zingbust@montana.com
Subject: \b refuses to work properly
Message-Id: <864343330.8912@dejanews.com>
Hi, I'm trying to write a search tool for my web site, such that
if someone searches on some words that are on a line or lines of
my database, the corresponding lines where a match occurs will be
returned to their browser. I want all searched words to be
boolean AND automatically. I don't want partial words to match,
so I have this snippet of code...
line: while ($string = <CITYFILE>) {
foreach $term (@terms) {
if ($string =~ /\b$term\b/i) {
$string =~ s#$highlight#<B>$&</B>#gio;
} # $highlight was earlier assigned the list of
# terms separated by a |, and surrounded by ()
else {
next line;
}
}
print "$string";
}
... This works fine for the first search term. The \b's prevent
a match on "clevelan" if the term is "cleveland". But, my
understanding of this stuff tells me it should also work on all
the terms. For example, the terms "Cleveland and "Robert"
are both on one line of my database. A search on "cleveland" and
"rober" returns a match when it shouldn't, yet reversing the order of
the two terms ("rober" first and then "cleveland) does not return a
match (as expected). Where has my thinking gone afoul?
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Thu, 22 May 1997 17:33:16 -0400
From: Nelson Asinowski <nelson@cae.ca>
To: isainfoserv@mindspring.com
Subject: Re: Baffled
Message-Id: <3384BB9C.7173@cae.ca>
RMO wrote:
> $found = "yes";
> foreach (@search_key) {
> if ($wholeline =~ m/$search_key[$l]/gi) {
> } else {
> $found = "no";
> }
> $l++;
> }
You need more practice in using perl technics. This code contains
severel problems
that combined could be the root of the program behaviour you have seen.
First instead of have the null statement {} change the binding operator
from
=~ to !~ and put >> $found = "no"; <<( this is also not the most
elegent way to do use booleans)
into the true side of the condition and get rid of the else.
Second you set up the foreach on the values of search_key and then you
never
use them. They are placed in $_ (local to the foreach loop).
All of the indexing and index incrementing is as if you were doing this
without
the foreach capability.
Your code would now become:
$found = "yes";
foreach (@search_key) {
if ($wholeline !~ m/$_/gi) {
$found = "no";
}
}
This only gets rid of the obvious misuse of perl syntax not any of your
logic problems.
--
Nelson Asinowski nelson@cae.ca
CAE Electronics Ltd. Montreal,Canada
------------------------------
Date: Thu, 22 May 1997 20:46:56 -0500
From: Matthew.Healy@yale.edu (Matthew D. Healy)
Subject: Re: Cross Platform CGI Programmer Needed
Message-Id: <Matthew.Healy-2205972046560001@pudding.med.yale.edu>
In article <comdog-1605970223570001@nntp.netcruiser>,
comdog@computerdog.com (brian d foy) wrote:
> cross platform CGI? hmmm... data are data. (i think i smell IIS.)
Indeed, methinks this may well lead one through the Gates to Hell, so
Eunuchs need not apply :-)
---------
As of 21 May 1997, 954 days till Y2K....
Matthew.Healy@yale.edu
http://paella.med.yale.edu/~healy
"But I thought it was pointed at the rabbit *between* my feet!"
---------
Help a victim of severe email harrassment, see
http://www.geocities.com/~hitchcockc/story.html#fund
---------
------------------------------
Date: Thu, 22 May 1997 21:57:07 -0400
From: "Otis Gospodnetic" <otisg@panther.middlebury.edu>
Subject: err compiling IO module
Message-Id: <5m2t5p$mva$1@tiger.middlebury.edu>
Hi,
I tried compiling IO module, version 1.15 on a BSDI with perl 5 on it, and
got these errors:
LD_RUN_PATH="" ld -o ./blib/arch/auto/IO/IO.none IO.o
IO.o: Undefined symbol _Perl_croak referenced from text segment
IO.o: Undefined symbol _Perl_stack_sp referenced from text segment
IO.o: Undefined symbol _Perl_markstack_ptr referenced from text segment
IO.o: Undefined symbol _Perl_stack_base referenced from text segment
IO.o: Undefined symbol _Perl_markstack_ptr referenced from text segment
IO.o: Undefined symbol _Perl_stack_base referenced from text segment
IO.o: Undefined symbol _Perl_croak referenced from text segment
IO.o: Undefined symbol _Perl_stack_base referenced from text segment
IO.o: Undefined symbol _Perl_sv_2io referenced from text segment
IO.o: Undefined symbol _fgetpos referenced from text segment
IO.o: Undefined symbol _Perl_newSVpv referenced from text segment
IO.o: Undefined symbol _Perl_sv_2mortal referenced from text segment
IO.o: Undefined symbol _Perl_stack_base referenced from text segment
IO.o: Undefined symbol _Perl_stack_base referenced from text segment
IO.o: Undefined symbol _Perl_sv_undef referenced from text segment
IO.o: Undefined symbol _errno referenced from text segment
IO.o: Undefined symbol _Perl_stack_base referenced from text segment
IO.o: Undefined symbol _Perl_stack_sp referenced from text segment
IO.o: Undefined symbol _Perl_stack_sp referenced from text segment
IO.o: Undefined symbol _Perl_markstack_ptr referenced from text segment
IO.o: Undefined symbol _Perl_stack_base referenced from text segment
IO.o: Undefined symbol _Perl_markstack_ptr referenced from text segment
IO.o: Undefined symbol _Perl_stack_base referenced from text segment
IO.o: Undefined symbol _Perl_croak referenced from text segment
IO.o: Undefined symbol _Perl_stack_base referenced from text segment
IO.o: Undefined symbol _Perl_sv_2io referenced from text segment
IO.o: More undefined symbol _Perl_stack_base refs follow
IO.o: Undefined symbol _fsetpos referenced from text segment
IO.o: Undefined symbol _errno referenced from text segment
IO.o: Undefined symbol _Perl_sv_newmortal referenced from text segment
IO.o: Undefined symbol _Perl_sv_setpvn referenced from text segment
IO.o: Undefined symbol _Perl_sv_setiv referenced from text segment
IO.o: Undefined symbol _Perl_stack_sp referenced from text segment
IO.o: Undefined symbol _Perl_stack_sp referenced from text segment
IO.o: Undefined symbol _Perl_markstack_ptr referenced from text segment
IO.o: Undefined symbol _Perl_markstack_ptr referenced from text segment
IO.o: Undefined symbol _Perl_croak referenced from text segment
IO.o: Undefined symbol _Perl_na referenced from text segment
IO.o: Undefined symbol _Perl_na referenced from text segment
IO.o: Undefined symbol _Perl_sv_2pv referenced from text segment
IO.o: Undefined symbol _tmpfile referenced from text segment
IO.o: Undefined symbol _Perl_sv_newmortal referenced from text segment
IO.o: Undefined symbol _Perl_newGVgen referenced from text segment
...
...
and so on....
...
IO.o: Undefined symbol _Perl_sv_yes referenced from text segment
*** Error code 1
Stop.
Can anyone help?
bets:/usr1/local/src/IO-1.15#perl -V
Summary of my perl5 (5.0 patchlevel 3 subversion 0) configuration:
Platform:
osname=bsdos, osver=2.0, archname=i386-bsdos
uname='bsdos bets.cois.com 2.0 bsdi bsdos 2.0 kernel #0: fri feb 3
17:51:37 mst 1995 polk@d
elos.bsdi.com:homepolkrelfoosyscompilegeneric i386 '
hint=previous, useposix=true, d_sigaction=define
Compiler:
cc='gcc', optimize='-O', gccversion=2.6.3
cppflags='-I/usr/local/include'
ccflags ='-I/usr/local/include'
stdchar='char', d_stdstdio=, usevfork=false
voidflags=15, castflags=7, d_casti32=define, d_castneg=define
intsize=4, alignbytes=4, usemymalloc=y, randbits=31
Linker and Libraries:
ld='ld', ldflags =' -L/usr/X11/lib -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib
libs=-ldld -lm -lc
libc=/usr/lib/libc.a, so=o
Dynamic Linking:
dlsrc=dl_none.xs, dlext=none, d_dlsymun=, ccdlflags=''
cccdlflags='', lddlflags=''
@INC: /usr1/local/lib/perl5/i386-bsdos/5.003 /usr1/local/lib/perl5
/usr1/local/lib/perl5/site_p
erl/i386-bsdos /usr1/local/lib/perl5/site_perl /usr1/local/lib/perl5/i386-bs
dos .
Thanks !
Otis
--
POPULUS, the Intelligent People Locator -- http://www.POPULUS.net/
------------------------------
Date: 18 May 1997 15:15:33 GMT
From: "Arathena Sprankle" <marien@goodnet.com>
Subject: getting started...
Message-Id: <01bc63f9$c9548fa0$268562cf@ibm-comp>
ok..
i figured out that you are supposed to create the file in notepad and then
test it in the dos box brought up when I execute perl.exe. However when I
tesed a simple file..
#! /perl/bin/perl
print "Hello, world!";
The file is kept in c:\hello.pl
perl.exe is in c:\perl\bin\perl.exe
when I type "perl c:\hello.pl"
I get an error "syntax error at - line 3, near "c:"
What exactly is happening here?
marien@goodnet.com
------------------------------
Date: 18 May 1997 09:05:32 GMT
From: "Arathena Sprankle" <marien@goodnet.com>
Subject: getting started..
Message-Id: <01bc63c6$1931cda0$0ffecccf@ibm-comp>
I am just getting started with learning how to pogram in perl in order to
make cgi scripts for my web page. I understand the language fairly
well....I have only one problem. How to get started? I downloaded perl 5.
Is this the right program to make my filename.pl files? When I tried to
write to the dos box opened when I exucuted perl.exe I couldn't save the
file from there. Instead I transfered it to notepad and saved it as
filename.pl. But how then do I test the file? I know I need to type "perl
filename.pl" while in the same dir but it doesn't work. I am running on Win
95/dos. If only I could get how to make and exxcute the files I will be
well on my way. PLease help.
marien@goodnet.com
------------------------------
Date: 23 May 1997 00:16:21 GMT
From: gossamer@glasswings.com.au (Bek Oberin)
Subject: Re: help - grep lines between two line patterns
Message-Id: <slrn5o9odb.c2k.gossamer@amarok.glasswings.com.au>
In article <8cn2pnftic.fsf@gadget.cscaper.com>, Randal Schwartz wrote:
>>>>>> "EtB" == Eli the Bearded <usenet-tag@qz.little-neck.ny.us> writes:
>EtB> [\x00-\xFF]*? # Smallest possible string of any char
>Or you can write:
> [\s\S]*?
>for that. I often do.
Hmmm. Would [\w\W]* or [\d\D]* both have the same effect?
I'm not sure why but I'd find the \w\W combination far more
'intuitive' than the others ..
gossamer
--
I gotta get a .sig file ...
------------------------------
Date: Thu, 22 May 1997 18:47:16 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: How to process logfiles with begin/end brackets?
Message-Id: <4ul2m5.e79.ln@localhost>
Craig Schenk (murple@ares.bsg.erols.net) wrote:
: I have a process which sets up web space, email, etc, for domains. It returns
: a log with a format like:
[ sample data snipped, see below ]
: There is a beginning "bracket" (* Command: domain,blah,blah,blah) and a closing
: one (* Command: Succeeded adding domain || * Command: Failed adding domain).
But there is also that '* =======' which proves handy for breaking
your data up into "records"...
: I need to associate all the lines between each set of "brackets" with the
: domain in question, as not all lines contain the domain name being processed.
: The ending bracket can take 2 forms. There can be multiple domains per log.
: What would be the most efficient way to do this?
--------------------------
#! /usr/bin/perl -w
$/ = "* =======\n"; # set the input record separator
while (<DATA>) {
chomp;
print "I am now processing \n-----\n$_-----\nas one chunk...\n\n";
}
__DATA__
* Command: eservice.com,eplee,No IPs,on,None,,PPP,Wildcard
>> Executing:ssh -l ns tool addrem eplee@eservice.com
>> Command returned: 0
>> >addrem: Done.
* Command: Succeeded adding eservice.com
* =======
* Command: gvimail.com,gvmail,No IPs,on,None,,PPP,Dot
>> Executing:ssh -l ns tool addrem .@gvimail.com
>> Command returned: 0
>> >addrem: Done.
* Command: Succeeded adding gvimail.com
* =======
--------------------------
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 22 May 1997 23:24:41 GMT
From: brieweb@aol.com (Brieweb)
Subject: Installing a Module in local directory
Message-Id: <19970522232400.TAA10665@ladder02.news.aol.com>
Sorry if this posted twice. Lost post did not take apparently.
The FAQ has the following answer for installing a module. Is there a
generic way to install a module in a local directory?
According to the faq located at
http://www.perl.org/CPAN/doc/FAQs/FAQ/PerlFAQ.html
>How do I install a CPAN module?
>The easiest way is to have the CPAN module do it for you. This module
comes with perl version 5.004 and later. To
>manually install the CPAN module, or any well-behaved CPAN module for
that matter, follow these steps:
> 1.Unpack the source into a temporary area.
> 2. perl Makefile.PL
> 3. make
> 4. make test
> 5. make install
>If your version of perl is compiled without dynamic loading, then you
just need to replace step 3 (make) with make perl
>and you will get a new perl binary with your extension linked in.
>See MakeMaker for more details on building extensions.
----------------
Brian Lavender
Napa, CA
Brie Business Directory - Napa Valley http://www.brie.com/bbd
(707) 226-8891
"Have you heard of the new improbability drive?"
------------------------------
Date: 22 May 1997 22:49:27 GMT
From: bill@sover.net.no.junkmail (Bill)
Subject: Re: Making a pool, but one man = one vote
Message-Id: <slrn5o9jbn.s2e.bill@granite.sover.net>
David Podeur wrote:
>
>Hi.
>
>I am trying to make a pool via the Internet, using cgi.
>
>
>The pool is aimed to students who have an account on a machine called
>vega. I have already make the form but what i need know is to be sure
>that no student can vote twice (or more...).
>
>Does anyone know a way to get get the student's username while he submits
>his form ?
>
>Thanks for your help.
>Pod.
This is more of a generic CGI question, which would be more
appropriately directed to comp.infosystems.www.authoring.cgi. But, the
bottom line is that you can't tell much of anything except the remote
user's hostname/IP address. Have them log in if you want to keep track
of them...
Bill
--
Sending me unsolicited email through mass emailing about a product or
service your company sells ensures that I will never buy or recommend your
product or service.
------------------------------
Date: 22 May 1997 19:03:37 -0500
From: kperrier@Starbase.NeoSoft.COM (Kent Perrier)
Subject: Re: Making a pool, but one man = one vote
Message-Id: <cszptnyrza.fsf@Starbase.NeoSoft.COM>
>
>David Podeur (podeurda@hpweb.utc.fr) wrote:
>: I am trying to make a pool via the Internet, using cgi.
>:
Cool! Let me know when you are done and I'll come over for a swim!
:)
Kent
--
Kent Perrier If Bill Clinton is the answer, then it must
kperrier@neosoft.com have been a really stupid question.
Corporations don't have opinions, people do. These are mine.
PGP 2.6 Public Key available by request and on key servers
PGP encrypted mail preferred!
------------------------------
Date: 22 May 1997 19:00:36 -0500
From: kperrier@Starbase.NeoSoft.COM (Kent Perrier)
Subject: Re: Members Only Section?
Message-Id: <cs206z12hn.fsf@Starbase.NeoSoft.COM>
In article <3384AA99.34C1@mail.eden.com>
Steph Spooner <spooner@mail.eden.com> writes:
>
>I am trying to create a web site that has a members only section that
>requires a password to enter that particular set of documents. I know I
>need a simple database with user name and password and also work with
>cookies. If anyone has any suggestions on where to look for a sample or
>can help please let me know.
>
A quick grep of the active newsgroups lists this newsgroup as one that has
cgi in the name:
comp.infosystems.www.authoring.cgi
May be you should ask there (perl != cgi ans cgi != perl).
Kent
--
Kent Perrier If Bill Clinton is the answer, then it must
kperrier@neosoft.com have been a really stupid question.
Corporations don't have opinions, people do. These are mine.
PGP 2.6 Public Key available by request and on key servers
PGP encrypted mail preferred!
------------------------------
Date: Fri, 23 May 1997 00:03:23 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: my(), foreach, and perl 5.004
Message-Id: <EALxHn.714@nonexistent.com>
On Thu, 22 May 1997 20:36:42 GMT, Richard S. Smith (rsmith@netcom.com) wrote
in comp.lang.perl.misc
<URL: news:rsmithEALnx6.LrJ@netcom.com>:
++ Hi. I was just wondering about the new feature in 5.004 that allows you to
++ use my() on the index of a foreach loop.
++
++ To be specific, I don't understand what this buys me. I mean, what's the
++ difference between "foreach $idx (@list)" and "foreach my $idx (@list)" ???
++
++ In each case I have an index variable $idx whose scope matches up with the
++ foreach loop, correct?
Uhm, no. With 'foreach my $idx (@list) { }' $idx goes out of scope
after the loop. With 'my $idx; foreach $idx (@list) { }' only the
value of $idx goes out of scope.
Compare:
#!/usr/local/bin/perl -w
use strict;
my $idx;
foreach $idx (1 .. 10) {;}
print $idx, "\n";
__END__
Use of uninitialized value at - line 5.
#!/usr/local/bin/perl -w
use strict;
foreach my $idx (1 .. 10) {;}
print $idx, "\n";
__END__
Global symbol "idx" requires explicit package name at - line 3.
Execution of tmp.pl aborted due to compilation errors.
I tended to do:
my $file;
foreach $file (@files) {something;}
...
# Still in same scope
my $file;
foreach $file (@files) {something else;}
That now generates a warning (I'm not too happy with that...)
But twice
foreach my $file (@files) {something else;}
is just fine.
Abigail
------------------------------
Date: 22 May 1997 22:39:42 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Need help with getting timezone from date
Message-Id: <5m301e$c5i@panix.com>
In <3383fa74.0@proxy.gist.net.au> huan@ns1.gist.net.au (Huan) writes:
>Does anybody know how to generate a date in perl which will show the timezone
>e.g. CST, GMT, UTC, EST, AST etc.
>OR
>show the offset to GMT.
>Is there a function in perl that will return the current timezone of the system.
Perl Modules are your friend. Look at this example:
#!/usr/local/bin/perl -w
use Date::Format;
$tz = time2str('%Z', time);
$offset = time2str('%z', time);
print "The Timezone is $tz ($offset from GMT)\n";
Output:
The Timezone is EDT (-0400 from GMT)
See: http://www.panix.com/~clay/perl/module.cgi?Date::Format
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: 22 May 1997 22:02:42 GMT
From: "Chris " <cmt@ucla.edu>
Subject: pattern matching/counting occurrences of text item
Message-Id: <01bc66fb$859525e0$af1543a4@LEIBNIZ>
I have a directory of dozens of files, each of which contains a number of
tags and
a corresponding value. For example:
<tag 1> foo
<tag 2> bar
.
.
.
Some tags repeat themselves several times in a file. For example, <tag 2>
may occur 5 times in one file, once in another, etc. Also, There are a
total of 10 possible values for <tag 1>, some of which are shared by many
files, although each individual file can contain only one tag. For example,
the value for <tag 1> in file 1 might be "foo", for file 2 "bar", and for
file 3 "foo" again, etc. What I want to do is extract certain data from
files which share the <tag 1> value, and group them together. In
particular, I want to search all the files for say, all the files which
have "foo" as
<tag 1>, and then I want to count how many times, say, <tag 2> occurs in
all of them. I then want to take the average and then print it out. The
code below, does what I want, except that it prints each iteration. Can
anyone recommend a simpler way of reaching this goal, perhaps with more
efficient pattern-matching usage? Thanks in advance,
ct
[note: this is not for a CGI-program!]
---
$filecount = 0;
while($filecount <= @ARGV-1) {
open (INFILE, $ARGV[$filecount]);
while ($input = <INFILE>) {
if ($input =~ /^<tag 1>/) {
chop($input);
@words = split(/[ \t]+/, $input);
if ($words[1] eq "foo") {
$num +=1;
&sub_foo($num);
}
}
}
}
sub sub_foo {
my($num) = @_;
while ($input = <INFILE>) {
if ($input =~ /^<tag 2>/) {
$count +=1;
}
}
print ("Total number of <tag 2>: $count\n");
print $num;
$ave = $count / $num;
print ("Average number of time <tag 2> appears: $ave\n");
print ("---------------------------------------------------\n");
}
------------------------------
Date: Thu, 22 May 1997 17:18:56 -0100
From: Scott <Scott@wwide.com>
Subject: questions about chop
Message-Id: <33848E10.43C8@wwide.com>
Hello,
I have text file full of lines that look like this:
blah stuff hmmm hello fred joe blue dd cc
I need to chop off the dd and cc on the end of all of them.. (they don't
really all say dd and cc, this is an example)
here is what I have:
while (<FILE>) { # reads into $_
print OUTFILE "<tr>";
foreach $field (split) { # split splits up $_ by
default
{
print OUTFILE "<td>$field</td>";
}
}
print OUTFILE "</tr>\n";
}
print OUTFILE "</table>\n";
close(FILE);
how do I use the chop command (or whatever one is necessary) to remove
the end of each line?
Is their a command to chop say 7 lines off of the end of every line?
Thanks in advance!
Scott
------------------------------
Date: Thu, 22 May 1997 18:35:29 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: regexp problem
Message-Id: <18l2m5.j39.ln@localhost>
Mr Simon Lee (silee@news.hk.super.net) wrote:
: I recently need to match the df output of the SunOS 4.1.x and
: SunOS 5.x. Their outputs are:
: SunOS 4.1.3:
: /dev/sda0 31199 13477 16111 46% /
: SunOS 5.x:
: /dev/dsk/c0t0d0s0 31199 13477 16111 46% /
: so I rsh to each machine, and get their df outputs, and do:
: (match all the chars and digits in the line, optionally
: match /\w+ e.g. /c0t0d0s0)
: if (m|(/dev/\w+(/\w+)?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(.*)|) {
: print "$1,$2,$3,$4,$5,$6\n";
: }
: I expect the outputs would be either:
: /dev/sda0,31199,13477,16111,46,/
: or
: /dev/dsk/c0t0d0s0,31199,13477,16111,46,/
I get no match at all with that data and that code.
Because there are no spaces between the '46' and the '%'...
[ snip output that is not produced by the script above... ]
: Does anyone know the correct answer ?
^^^^^^^^^^^^^^^^^^
split()
-------------------
#! /usr/bin/perl -w
while (<DATA>) {
@parts = split /%?\s+/;
foreach (@parts) {print "'$_' "}
print "\n";
}
__DATA__
/dev/sda0 31199 13477 16111 46% /
/dev/dsk/c0t0d0s0 31199 13477 16111 46% /
-------------------
: Thanks,
You're welcome.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Thu, 22 May 1997 20:51:05 -0400
From: "Jason A. Soloff" <jsoloff@psu.edu>
Subject: RegExp tutorial suggestions?
Message-Id: <3384E9F9.521D078C@psu.edu>
Hi all..
Does anyone know of a good regexp tutorial or FAQ online?
Doesn't have to be incredibly perl heavy, just explain how to
set up and use the regexps...
Thanks,
Jason
------------------------------
Date: Thu, 22 May 1997 16:20:39 +0000
From: Doyle Tracy <doyle@teleport.com>
Subject: Some PERL questions...
Message-Id: <33847257.D3814132@teleport.com>
I'm doing some research on PERL and the language is VERY new to me. I
was wondering if anyone would be willing to answer some questions for
me:
1. Does PERL evaluate AND and OR with or without short-circuiting?
2. Does PERL perform any implicit type conversions?
If so, what are they?
3. What does PERL use for type equivalence, domain, name, or
declaration?
4. What is the domain of the allowable intergers?
What is the domain of reals?
If anyone can help it would be VERY useful to me. Thank you in advance.
Thanks,
Doyle Tracy
------------------------------
Date: 22 May 1997 22:39:29 GMT
From: ewj@sunquest.com (Edward Jajko (The Nekomancer))
Subject: Re: Split function
Message-Id: <5m2hv1$55q$1@iggy.sunquest.com>
In article <3384A1FC.15FB7483@uu.net>, Dale Johnson <djohnson@uu.net> wrote:
>> If you are looking to split a line that might have delimiters of
>> colon(:),
>> slash(/), or by whitespace(/s), then you might want to use this:
>>
>> @array = split(/[:|\\|\s]/, $string);
This does more than it's supposed to- it also splits on |
@array=split/[:\\\s]/, $string); #correct version
------------------------------
Date: Fri, 23 May 1997 00:42:19 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: split'\|'; except when preceded by '/'
Message-Id: <EALzAJ.A4p@nonexistent.com>
On Thu, 22 May 1997 15:03:08 -0400, Dan Boorstein (danboo@ixl.com) wrote in
comp.lang.perl.misc
<URL: news:3384986C.4A19A768@ixl.com>:
++ Hello All,
++
++ Here is the problem.
++
++ A string with: no linefeeds
++ fields separated by |
++ nested |'s are escaped with \ (i.e., \|)
++
++ I want to split this string on unescaped |'s, removing
++ the \'s preceding the escaped |'s. I thought this would
++ be a 2 line split-regex block, but has turned into
++ something much less elegant which I pieced together
++ from various FAQ's and Dejanews articles. Behold:
++
++ $_ = '\||split|me|\|<no split|1\|=\|1|3|' . 'EOQ';
++ @temp = split'\|';
++ for ($i = 0; $i <= $#temp; $i++){
++ $field = $temp[$i];
++ while ($field =~ s/\\$/|/) { $field .= $temp[++$i]; }
++ push(@fields, $field);
++ }
++ $fields[$#fields] =~ s,EOQ$,,;
++
++ for(@fields) { print $_, "\n"; }
++
++ After execution @fields contains (as expected):
++ ('|','split','me','|<no split','1|=|1','3','')
++
++ It does everything I wanted it to do, but not as cleanly as I'd
++ hoped. Any ideas on how to clean up this process (not necessarily
++ my coding style)?
Perl has a zero width negative lookahead (?!expr) to match something
which is not followed by expr. Unfortunally, it cannot be used as a
lookbehind, which is what we want, a | not preceded by a \.
But what if we get creative? If what we want to match is reversable
and what we not want to match in the lookbehind is reversable too,
we can reverse the string and the (sub)regexs and the lookbehind
becomes a lookahead. In our case, the match is '|', and the lookbehind
a '\' which are trivially reversed.
So we reverse the string, and then split on | not followed by \.
The regular expression for that is: /\|(?!\\)/. Note that we need to
escape the | and the \. So we start out with:
split /\|(?!\\)/, reverse $_;
But now all our terms are reversed, and they are in reversed order.
So we need two reverses to undo. To reverse each term, we use a map,
and put in a scalar to force scalar context, so reverse will reverse
the string:
@fields = reverse map {scalar reverse $_;} split /\|(?!\\)/, reverse $_; # [*]
Hmmm, but that still leaves the \| in, so we need to fix that foreach
term. We need to add something to the map. I prefer doing it before
the reverse, so we need to change |\ to | (and don't forget the g flag):
@fields = reverse map {s/\|\\/|/g; scalar reverse $_;}
split /\|(?!\\)/, reverse $_;
The complete program:
#!/usr/local/bin/perl -w
use strict;
$_ = '\||split|me|\|<no split|1\|=\|1|3|';
my @fields = reverse map {s/\|\\/|/g; scalar reverse $_;}
split /\|(?!\\)/, reverse $_;
print map {"$_\n";} @fields;
__END__
|
split
me
|<no split
1|=|1
3
Abigail
[*] Can I coin this ``Abigail transform''?
------------------------------
Date: 22 May 1997 21:05:31 -0400
From: Chaim Frenkel <chaimf@cris.com>
To: Dan Boorstein <danboo@ixl.com>
Subject: Re: split'\|'; except when preceded by '/'
Message-Id: <m33erfgfqc.fsf@nlk.nlk.com>
>>>>> "DB" == Dan Boorstein <danboo@ixl.com> writes:
DB> Hello All,
DB> Here is the problem.
DB> A string with: no linefeeds
DB> fields separated by |
DB> nested |'s are escaped with \ (i.e., \|)
DB> I want to split this string on unescaped |'s, removing
DB> the \'s preceding the escaped |'s. I thought this would
DB> be a 2 line split-regex block, but has turned into
DB> something much less elegant which I pieced together
DB> from various FAQ's and Dejanews articles. Behold:
Since there are no linefeeds (untested)
$line =~ s/\\\|/\n/g;
@array = map {tr/\n/|/} split(/\|/, $line);
or
$line =~ s/\|/\n/g; # All | into \n
$line =~ s/\\\n/|/g; # All escaped \n into |
@array = split(/\n/,$line);
<chaim>
--
Chaim Frenkel Nonlinear Knowledge, Inc.
chaimf@cris.com +1-718-236-0183
------------------------------
Date: 22 May 1997 23:48:09 GMT
From: gossamer@glasswings.com.au (Bek Oberin)
Subject: Re: Why doesn't this simple script work?
Message-Id: <slrn5o9moe.c2k.gossamer@amarok.glasswings.com.au>
In article <t59117dvcg.fsf@solo.tecelite.com>, Skip Koppenhaver wrote:
>I'm a perl newbie and I can't figure out why this simple script won't do
>what I want it to. It's supposed to squeeze multiple blank lines into one
>blank line. If there's a better way of doing this, please tell me. But I'd
The cannonical way of doing this (ie: the one in the Camel book)
is:
perl -ne 'print if /\S/ || !$s; $s = /^\s*$/;'
which will run from the command line, you'd make it into a script
like this (with comments added):
while (<>) {
chop; # remove the newline from the end of $_
print if /\S/ || !$s; # print $_ if either this line contains
# some non-whitespace, OR if $s is
# false (ie: the previous line contained
# some real characters)
$s = /^\s*$/; # set $s to true if there is only whitespace
}
>also like to know why this script doesn't work. Thanks.
>while (<>) {
> # Squeeze multiple blank lines into one
> if ($_ eq "\n" && $prevLine eq "\n") {
> next;
> }
> $prevLine = $_;
> print;
>}
Actually, it does work when I tested it and the logic is basically
the same as the previous one although your way of writing it out is
more verbose. It's less useful than the script above though because
your script thinks that a line with only spaces and/or tab characters
on it isn't blank, when it looks blank. I'd guess you tested it on a
file whose 'blank' lines weren't really blank.
>Please email me the answer since I don't usually read this newsgroup.
This is about the best way to guarantee you won't gt an answer to
your question, BTW. Don't you think that since you're asking us
to help you could at least put out a little effort to make sure you
see the answers??
gossamer
------------------------------
Date: 23 May 1997 01:49:23 GMT
From: marti@netrail.net (Dennis Marti)
Subject: Re: yyyymmdd from localtime?
Message-Id: <5m2t33$c1f$1@skipper.netrail.net>
felix k sheng (felix@chance.em.nytimes.com) wrote:
: On 22 May 1997 14:51:47 GMT, felix k sheng wrote:
: >On Wed, 21 May 1997 16:32:38 -0400, Vincent Kargatis
: ><kargatis@jackaldog.gsfc.nasa.gov> wrote:
: >>I want to get a YYYYMMDD from localtime. [chomp]
:
: here's another shorter and even uglier version!
: sprintf( "19%02d%02d%02d", map { $_+=1-($x^=1) } (localtime)[5,4,3] );
Ever wonder where all the hoo ha about Y2K comes from?
Putting 19 in front of the (localtime)[5] value is not a good idea.
localtime returns the number of years since 1900. On May 22, 2001 that
value will be 101, and the result of the sprintf above will be
"191010522". Believe that your code will be running somewhere in three
years.
I don't understand the need to get this on one line, so here it is on
two:
my($day, $month, $year) = (localtime)[3,4,5];
my $date = sprintf "%04d%02d%02d", $year+1900, $month+1, $day;
You could always do something like this to it:
($d,$m,$y)=(localtime)[2..5];$t=sprintf"%04d%02d%02d",$y+1900,$m+1,$d;
yech.
I hope this helps,
Dennis Marti
------------------------------
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 519
*************************************