[7546] in Perl-Users-Digest
Perl-Users Digest, Issue: 1172 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 14 02:07:58 1997
Date: Mon, 13 Oct 97 23:00:32 -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 Mon, 13 Oct 1997 Volume: 8 Number: 1172
Today's topics:
Re: [Q] Search/replace within text file (Tad McClellan)
Database Management in UNIX dominic@thiru.vetri.com
Getting date manip to work (Craig Giffen)
Re: Help embedding html tag in output (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Help: Text Formatter in Perl (Blackthorne)
How to extract substrings out of a line? (John Robson)
Re: How to extract substrings out of a line? (Tad McClellan)
Re: How to extract substrings out of a line? (brian d foy)
How to set for chmod so getcwd will work from HTTP. franklin@ideas4you.com
Re: How to set for chmod so getcwd will work from HTTP. (brian d foy)
Re: JAVASCRIPT in PERLSCRIPTS <sitruc@ix.netcom.com>
Re: JAVASCRIPT in PERLSCRIPTS <sitruc@ix.netcom.com>
Re: Need RE to change overstrikes to HTML <bholzman@mail.earthlink.net>
Re: newbie: counting patterns <bholzman@mail.earthlink.net>
Re: NEWBIE: How to read a file into a scalar <bholzman@mail.earthlink.net>
Re: Perl for Win32 in cgi <jurlwin@access.digex.net>
Re: Problems compiling perl under Solaris 2.5.1 jkstill@teleport.com
Re: reg exp size limit !? <bholzman@mail.earthlink.net>
Re: reg exp size limit !? (Tad McClellan)
Re: reg exp size limit !? (Mike Heins)
Re: Reg expr. question (SEARCH and REPLACE) (Tad McClellan)
Re: Reg expr. question (SEARCH and REPLACE) (brian d foy)
Re: uninitialized value warning for m// substrings (brian d foy)
Re: uninitialized value warning for m// substrings (Daniel S. Lewart)
Writing/Reading Binary Files (James A. Kivisild)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 14 Oct 1997 00:01:38 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: [Q] Search/replace within text file
Message-Id: <ibuu16.i54.ln@localhost>
Adam Grayson (a-grayson@nwu.edu) wrote:
: I am working on a script to open up a semi-database -- actually a text
: file set up like this:
: value 1a <TAB> value 2a <TAB> value 3a
: value 1b <TAB> value 2b <TAB> value 3b
Nothing 'semi' there. That is indeed a database.
: Once a certain action is performed upon one of the database entries
I don't know what this means, but I probably don't need to, since
you didn't explain the action to us ;-)
: (i.e. value 1b, 2b, 3b), I would like to delete that line from the text
: file.
read lines from DB file, write (some) lines to a temp file,
move the temp file over the DB file
(this won't be good enough
if this DB is used by multiple processes, but you didn't say
anything about multiple process or running as a CGI, so that
probably doesn't matter either ;-)
: The first value on each line is unique within the whole file,
The first value on each line is the key.
: replication of that first value is not a concern in writing the
: function.
I don't know what you mean there either...
: When I import each line into the script, I set it up as such:
: $fields[0]
: .
: .
: $fields[n]
OK, I will too then ;-)
: So, if (based on my first example) I was done with the line containing
: values 1b, 2b and 3b, I would like the entire second row deleted or
: replaced by a series of empty spaces.
: Any help would be immensely appreciated.
UNTESTED
open(DB, 'myDBfile') || die "could not open 'myDBfile' $!";
# not a very good temp file name though
open(OUT, ">tempDB.$$") || die "could not open 'tempDB.$$' $!";
while (<DB>) {
@fields = split /\t/;
if ($I_want_to_keep_this_record) { # don't write it if you don't want it
print OUT;
}
}
close(DB);
close(OUT);
rename "tempDB.$$", 'myDBfile';
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 14 Oct 1997 00:21:25 -0600
From: dominic@thiru.vetri.com
Subject: Database Management in UNIX
Message-Id: <876805928.12490@dejanews.com>
Hello Perlians,
I regret if it is a repeated question.
So far I have been using Perl for Win32 in Win95 and Win NT machines. In
that I was using Dave Roth's Win32::ODBC module without any problem. Now
I have to use something like a database management utility in my unix
system.
I need to do the following in my UNIX machine
1. Create a new database with 5 fields (or more).
2. Add record(s) to that new database file.
3. Grep some records and modify it and update it in the database.
4. Delete some records with some specific field name.
5. Generate a report (something like using SQL statement).
Is would like to know whether these are possible in UNIX side using a
perlscript?
Is there any ready-made modules available?
Is there any sample PerlScript available?
Kindly point me to the right direction.
Thanks a lot for your help.
Dominic
________________________________________________________
For Win32Perl Mail Archive-Visit (5200 mails)
http://www.geocities.com/SiliconValley/Heights/9736
________________________________________________________
A. Dominic, Project Leader, Work: +91 44 8240665
Vetri Software, 160 Grams Road, Home: +91 44 4925590
Madras, India
Email: dominic@thiru.vetri.com
________________________________________________________
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Tue, 14 Oct 1997 05:46:40 GMT
From: cgiffen@teleport.com (Craig Giffen)
Subject: Getting date manip to work
Message-Id: <61utfv$7aa$1@news1.teleport.com>
I'm a little in the grey area regarding the date manipulator module
that is on CPAN. What exactly has to be done to use this module? Is
it most likely on my server already? If it is, what is the "require"
line I need to put into my script in order to use the &dateparse
subroutines.
I'm just trying to take a certain date and and x amount of days to it
and print the result.
Thanks
Craig
cgiffen@teleport.com
------------------------------
Date: Mon, 13 Oct 97 22:39:55 -0400
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: Help embedding html tag in output
Message-Id: <3442dc77$1$ofn$mr2ice@speaker>
In <344218D6.7F77@cais.com>, on 10/13/97 at 08,
Chris Welch <cwelch@cais.com> said:
+-----
| Am I even on the right track ? I've tried the following:
| $tserved =~ tr'$fstate'<b>$fstate</b>';
+--->8
Two problems:
(1) tr/// maps characters, it does not substitute strings. You probably want
to use s///.
(2) Using singlequote as the delimiter keeps Perl from expanding the variable.
Use something else instead. (You don't have to avoid any character that might
be present in the variable's value, only those present in the variable's
name.)
--
brandon s. allbery [Team OS/2][Linux] bsa@void.apk.net
cleveland, ohio mr/2 ice's "rfc guru" :-) KF8NH
Warpstock '97: OS/2 for the rest of us! http://www.warpstock.org
Memo to MLS: End The Burn Scam --- Doug Logan MUST GO! FORZA CREW!
------------------------------
Date: 13 Oct 1997 22:56:44 GMT
From: sean@delphi.glendon.yorku.ca (Blackthorne)
Subject: Help: Text Formatter in Perl
Message-Id: <61u8vc$89l$1@sunburst.ccs.yorku.ca>
[ Article reposted from comp.lang.perl ]
[ Author was Blackthorne <sean@delphi.glendon.yorku.ca> ]
[ Posted on 13 Oct 1997 08:36:25 GMT ]
Greetings...
Does anyone know where or if there is a Perl Programme out there in some
archive that formats text? I'm basically looking for something that will
take an input text file, format the text so that borders will conform to
whatever number I pick and make the file look all nice and readable.
If there are any crazy souls out there that are thinking to themselves
'Hey, that's a good idea' and are thinking of coding one. Your welcome
to email me, because I also have a file with the specifics/specs of what
I'm looking for.
Right now, I'm looking to see if there is already an existing file out there
in some archive. But if anyone is crazy enough to want to code it for me
and themselves, they are welcome to contact me. I really don't have the time
to learn Perl and code it myself.
--
Cajun Nights Mush /> Later...
Cajun.Targonia.com 7373 /< Cry Havok and let Slip the Dogs of War
[\\\\\\\\\\(O):::<======================================-
Http://www.geocities.com/ \< Blackthorne@delphi.glendon.yorku.ca
BourbonStreet/1373/ \> Blackthorne.
--
Cajun Nights Mush /> Later...
Cajun.Targonia.com 7373 /< Cry Havok and let Slip the Dogs of War
[\\\\\\\\\\(O):::<======================================-
Http://www.geocities.com/ \< Blackthorne@delphi.glendon.yorku.ca
BourbonStreet/1373/ \> Blackthorne.
------------------------------
Date: 13 Oct 1997 22:45:19 GMT
From: as646@FreeNet.Carleton.CA (John Robson)
Subject: How to extract substrings out of a line?
Message-Id: <61u89v$s0t@freenet-news.carleton.ca>
$line = "testing: 7/100 45/100 30/50"
Would like to extract 7, 45 and 30 from $line and store them in the array
@mynumbers. Why doesn't this work ? How to do this ?
if ( $line =~ (/[0-9]+\//) )
{
push(@mynumbers, $1);
}
------------------------------
Date: Mon, 13 Oct 1997 23:30:31 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: How to extract substrings out of a line?
Message-Id: <7hsu16.234.ln@localhost>
John Robson (as646@FreeNet.Carleton.CA) wrote:
: $line = "testing: 7/100 45/100 30/50"
: Would like to extract 7, 45 and 30 from $line and store them in the array
: @mynumbers.
push(@mynumbers, $1) while $line =~ m!(\d+)/!g;
: Why doesn't this work ?
1) You want to match more than one number, but you have neither a loop
nor m//g, so you're only going to get one
2) The parenthesis go _inside_ of the regular expression
(the edges of the regex are the regex delimiters, underlined below)
: How to do this ?
3) If my pattern has a literal slash in it, then I nearly always
go with alternative regex delimiters rather than backwack the slash.
4) Perl already has a shorthand for [0-9], namely \d
: if ( $line =~ (/[0-9]+\//) )
^ ^
^ ^
: {
: push(@mynumbers, $1);
: }
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 14 Oct 1997 01:21:25 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: How to extract substrings out of a line?
Message-Id: <comdog-ya02408000R1410970121250001@news.panix.com>
In article <61u89v$s0t@freenet-news.carleton.ca>, as646@FreeNet.Carleton.CA (John Robson) wrote:
>$line = "testing: 7/100 45/100 30/50"
>
>Would like to extract 7, 45 and 30 from $line and store them in the array
>@mynumbers.
how about:
@my_numbers = ($line =~ m|
\d+ #some number of digits
(?=/) #followed by a slash
|xg); #eXtended format, Global match
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Mon, 13 Oct 97 23:20:30 -0400
From: franklin@ideas4you.com
Subject: How to set for chmod so getcwd will work from HTTP.
Message-Id: <3442e55a$1$senaxyva$mr2ice@news.alltel.net>
I've tried several things and can't seem to get anyone of them to work. I
need to use the getcwd command to work when the script is run via the WWW.
The script works via telnet. It just won't work when accessed through
HTTP.
--
Coming Soon,
"Discussion Groups" the power of the news groups packed into the manageablity of a mail list.
Ideas Unlimited Consulting
http://www.ideas4you.com
------------------------------
Date: Tue, 14 Oct 1997 01:24:15 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: How to set for chmod so getcwd will work from HTTP.
Message-Id: <comdog-ya02408000R1410970124150001@news.panix.com>
In article <3442e55a$1$senaxyva$mr2ice@news.alltel.net>, franklin@ideas4you.com wrote:
>I've tried several things and can't seem to get anyone of them to work. I
>need to use the getcwd command to work when the script is run via the WWW.
>The script works via telnet. It just won't work when accessed through
>HTTP.
there are no special commands for WWW scripts.
see the Perl CGI troubleshooting guide to see if you can spot your
problem. if you can't, then post the relevant bits of code.
[1]
<URL:http://language.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html>
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Mon, 13 Oct 1997 20:58:12 +0000
From: sitruc <sitruc@ix.netcom.com>
Subject: Re: JAVASCRIPT in PERLSCRIPTS
Message-Id: <34428B64.5029@ix.netcom.com>
I don't know if it was your comment tags surrounding the code, but the
following (with a return set to come back on screen) works (should work
for both UNIX and NT). You can also set javascript cookies with perl
strings, as shown. You could also use Matt's Perl Cookie subroutines
(all housed in one little handy library) available at
www.worldwidemart.com/scripts...hope this helped!
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
$cookievar = "perlString";
print "<HTML><BODY>\n";
print "<SCRIPT LANGUAGE=\"Javascript\">\n";
print "var text=\"$cookievar\"\n";
print "document.cookie=text\n";
print "alert(\"$cookievar\")\n";
print "document.writeln('Your cookie (' + text + ') was set')\n";
print "</SCRIPT>\n";
print "</BODY></HTML>\n";
exit;
Note: when setting the cookie and writing to the screen, the perl string
($cookievar) and the JS variable (text) are interchangable.
-sitruc
------------------------------
Date: Mon, 13 Oct 1997 21:09:47 +0000
From: sitruc <sitruc@ix.netcom.com>
Subject: Re: JAVASCRIPT in PERLSCRIPTS
Message-Id: <34428E1C.7E9C@ix.netcom.com>
I wasn't paying any attention and I think I posted this wrong...so here
it is again.
# when setting the cookie and writing to the screen
# The perl string ($cookievar) and the JS variable (text) are
interchangable
print "Content-type: text/html\n\n";
$cookievar = "perlString";
print "<HTML><BODY>\n";
print "<SCRIPT LANGUAGE=\"Javascript\">\n";
print "var text=\"$cookievar\"\n";
print "document.cookie=text\n";
print "alert(\"$cookievar\")\n";
print "document.writeln('Your cookie (' + text + ') was set')\n";
print "</SCRIPT>\n";
print "</BODY></HTML>\n";
exit;
could've been your comment tags around the script. This should work in
both UNIX and NT
------------------------------
Date: Mon, 13 Oct 1997 22:12:38 -0400
From: Benjamin Holzman <bholzman@mail.earthlink.net>
To: Clinton Pierce <cpierce1@cp501.fsic.ford.com>
Subject: Re: Need RE to change overstrikes to HTML
Message-Id: <3442D516.D58A509D@mail.earthlink.net>
Clinton Pierce wrote:
>
> I've been diddling with this for couple of hours now, and want to
> know if anyone has a clever way of doing this?
>
> Given input text that looks like:
>
> t^Ht^Ht^Hh^Hh^Hh^He^He^He^H q^Hq^Hq^Hu^Hu^Hu^Hi^Hi^Hi^Hc^Hc^Hc^Hk^Hk^Hk^H
>
> (the phrase "the quick" with 3 backspace-overstrikes per letter)
>
> Is there a simple RE that will change the text to:
>
> <B>the quick</B>
>
> I won't embarass myself by posting my attempts at getting this to work.
> Can anyone help?
You didn't explicitly say it, but I assume that the text with
backspace-overstrikes is embedded within some other, normal text. This
will be easier if we split up each line into words, and try to fix one
word at a time:
my $bold = '<B>';
my $whitespace = '';
while (<>) {
my @words = split /(\s+)/;
my $line = '';
for ($i=0;$i<@words;$i++) {
next unless $words[$i];
if ($words[$i] =~ /\s+/) {
$whitespace .= $words[$i];
} elsif ($words[$i] =~ s/(\w)\b(?:\1\b){2}/$1/g) {
$line .= "$whitespace$bold$words[$i]";
$bold = $whitespace = '';
} elsif ($bold) {
$line .= $whitespace.$words[$i];
$whitespace = '';
} else {
$line .= "</B>$whitespace$words[$i]";
$bold = '<B>'; $whitespace = '';
}
}
print $line; #or do whatever you want...
}
This got a little complicated because I kept improving it, but it has
the advantages of only processing one line at a time, which is nice if
your input file is big, and the bold/endbold tags are pretty smart about
whitespace-- any whitespace between bold words stays inside while any
whitespace outside bold words stays outside. You can even have many
newlines in the middle of a bold section, and all will be hunky-dory.
HTH,
Benjamin Holzman
------------------------------
Date: Mon, 13 Oct 1997 21:09:07 -0400
From: Benjamin Holzman <bholzman@mail.earthlink.net>
Subject: Re: newbie: counting patterns
Message-Id: <3442C633.5EBB07D4@mail.earthlink.net>
> if the pattern is more complicated than a single character:
>
> $count=()=/$pattern/g; #perl5.004 or better only
> or perhaps
> $count=@{[/$pattern/g]};
I can't tell you how much I love this expression :-)
> or even
> $count=s/($pattern)/$1/g;
I wonder if this is less efficient than the previous two...
>
> (assuming the line is in $_ ... efficiency concerns left
> as an excersise :-)
>
> regards
> andrew
------------------------------
Date: Mon, 13 Oct 1997 21:06:47 -0400
From: Benjamin Holzman <bholzman@mail.earthlink.net>
Subject: Re: NEWBIE: How to read a file into a scalar
Message-Id: <3442C5A7.6A4A5064@mail.earthlink.net>
[posted & mailed]
Tikki tikki tembo-no sa rembo-chari bari ruchi-pip peri pembo wrote:
>
> I'm trying to read a text file into a scalar. I was originally just
> setting the scalar equal to the filehandle, but I got coredumps when
What exactly do you mean by 'setting the scalar equal to the
filehandle'?
> the file was too big. I tried using the read command from page 170 of
> the camel book, but it would only work properly when LENGTH was set to
> 16000 or less (any more, and the script would hang or give memory
> errors), and when the file was smaller than LENGTH.
Um, which camel book are you referring to? If it's purplish/pink,
you've got the old version. You should really get the new version; it
has an attractive turquoise cover and can likely be found in your campus
bookstore. In it, on page 202, you'll find the following code:
while (read FROM, $buf, 16384) {
print TO $buf;
}
Keeping in mind that perl's read() is simply a front-end to your
system's fread() call, I suppose there may be some memory limitations
there, but I bet the read() command takes most of them into account. In
any event, you could modify the above code to something like this:
while (read FROM, $buf, some_number_which_doesn't_core_dump) {
$string .= $buf;
}
The traditional way to read a complete file into a string is this:
local($/) = undef;
my($string)=<FILE>;
This will certainly give you problems if your file is larger than can
comfortably fit in memory. It can also be quite inefficient, especially
if you then turn around and try to do some pattern matching on the whole
string. If neither of these solutions work for you, perhaps perl is
not installed correctly. You could try building your own perl if you
have access to a c compiler. HTH,
Benjamin Holzman
>
> I am using Perl 5.003 on a machine running HP-UX 10.10. I don't think
> any Perl extras have been installed, and I don't have ready access to
> anyone with root on the machine. Please help.
>
> Thanks,
> Joanna the Frustrated Perl Newbie
>
> --
> ]:o_ o/
> |O = joanna l. salgado __ computer greek (delta gamma) ___|--
> |_o= shower philosopher calliope@leland.stanford.edu \
> @ `
------------------------------
Date: Mon, 13 Oct 1997 23:01:49 -0400
From: "Jeff Urlwin" <jurlwin@access.digex.net>
Subject: Re: Perl for Win32 in cgi
Message-Id: <61und9$m0n$1@news2.digex.net>
Check out my page, below. It gives (what should be) enough
instructions...and a sample, to boot.
jeff
--
Jeff Urlwin
http://www.access.digex.net/~jurlwin
Paul D. Chapin wrote in message <34423b51.0@amhnt2.amherst.edu>...
>Is it possible to create a perl cgi script that will run with the
>Personal Web Server on a Win95 system and, if so, how? Unfortunately,
>the documentation on both the perl and server side are a little weak
>on this.
>
>Why would I want to do this you might add. Well, we've been letting
>our users write cgi scripts that run on our UNIX server. This is
>generally a very bad idea. We've also been considering replacing the
>UNIX server with an NT based server. The idea is that we'll block
>individuals from running cgi scripts on our server and tell them that
>if they really want to have a cgi script, set up their own personal
>server and run the scripts there. However, for this to work, there
>has to be a relatively painless way of running the scripts - as
>painless as the shebang notation that can be used with UNIX.
>
>--
>
>Paul Chapin
>pdchapin@unix.amherst.edu
>Unix Systems Manager I'm too busy to have time
>Amherst College for anything important.
>413-542-2144
------------------------------
Date: Tue, 14 Oct 1997 03:22:53 GMT
From: jkstill@teleport.com
Subject: Re: Problems compiling perl under Solaris 2.5.1
Message-Id: <3442e56e.66903563@news.teleport.com>
On Mon, 13 Oct 1997 16:09:56, in comp.lang.perl.misc you wrote:
>I have been trying to compile per l5.004_01 on a Solaris 2.5.1 machine with
>Sun's C compiler. I get errors such as:
You can't build Perl with Sun's compiler. At least I couldn't.
You need to use gcc. Don't use GNU's 'ld' or 'as' though, you will
need to use Sun's version of those.
Confused yet?
Scan usenet with www.altavista.digital.com or some other search engine
to find more references to building Perl on Solaris.
Jared Still
Oracle DBA and Part Time Perl Evangelist ;)
jkstill@bcbso.com - work
jkstill@teleport.com - home
------------------------------
Date: Mon, 13 Oct 1997 21:22:00 -0400
From: Benjamin Holzman <bholzman@mail.earthlink.net>
To: sartang@pcocd2.intel.com
Subject: Re: reg exp size limit !?
Message-Id: <3442C938.D85065E0@mail.earthlink.net>
sartang@pcocd2.intel.com wrote:
>
> is there a limit on how big a string can be used
> for matching in a regular expression. I'm having
> this difficulty with size of the string.
>
> using something like this :
>
> if ( /keyword (\(.+\))/ )
>
> where .+ may be very very long. And perl
> doesn't match it if it is long. Is there a
> way to extend this limit if there is one.
> It fails to match it if it's over 32786 characters.
I didn't have any problems using that pattern to match strings much
larger than that. What version of perl are you using?
>
> thanks
> saviz
>
> -------------------==== Posted via Deja News ====-----------------------
> http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Mon, 13 Oct 1997 23:19:19 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: reg exp size limit !?
Message-Id: <7sru16.o04.ln@localhost>
Eli the Bearded (usenet-tag@qz.little-neck.ny.us) wrote:
: Posted and mailed.
: <sartang@pcocd2.intel.com> wrote:
: > is there a limit on how big a string can be used
: > for matching in a regular expression. I'm having
: Yes.
: > It fails to match it if it's over 32786 characters.
: :r! man perl | grep -C 3276
: longer than 255 characters, and no component of your PATH
: may be longer than 255 if you use ----SSSS. A regular
: expression may not compile to more than 32767 bytes
: internally.
: Probably should be mentioned in the perlre manpage as well, but,
: oh well.
Just to be clear here, Eli interpreted your question to be about
the size of the compiled regular expression.
Just in case your question is about the size of the string to be
matched, rather than the size of the regex, it is limited only by
your system's available memory.
There is something else wrong (unless you really are running
out of memory ;-)
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: 14 Oct 1997 05:16:53 GMT
From: mheins@prairienet.org (Mike Heins)
Subject: Re: reg exp size limit !?
Message-Id: <61uv85$5m8$1@vixen.cso.uiuc.edu>
Eli the Bearded (usenet-tag@qz.little-neck.ny.us) wrote:
: Posted and mailed.
:
: <sartang@pcocd2.intel.com> wrote:
: > is there a limit on how big a string can be used
: > for matching in a regular expression. I'm having
:
: Yes.
:
: > It fails to match it if it's over 32786 characters.
:
: :r! man perl | grep -C 3276
: longer than 255 characters, and no component of your PATH
: may be longer than 255 if you use ----SSSS. A regular
: expression may not compile to more than 32767 bytes
: internally.
:
: Probably should be mentioned in the perlre manpage as well, but,
: oh well.
I think we have a failure to understand the problem in all of
the followups to date.
First of all, the man reference above refers to the COMPILATION
SIZE of the regex, not the size of the scanned string. You will
find it difficult to write one that compiles that big. 8-)
The scanned string can be any size. I routinely do multiple
regex scans of strings hundreds of Kbytes long, and often
do simple regexes on multi-megabyte files.
No doubt your problem is this atom:
.+
That will not match a newline, so you need to
either add the /s modifier to the regex or
change the atom to:
[\000-\377]+
--
Regards,
Mike Heins
This post reflects the
opinion of my employer.
------------------------------
Date: Mon, 13 Oct 1997 23:42:17 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Reg expr. question (SEARCH and REPLACE)
Message-Id: <97tu16.844.ln@localhost>
Vinny Carpenter (vscarpenter@qgraph.com) wrote:
: hi guys.. I have a question that I'm hoping someone can answer. Using
: Perl on a Linux
: box. Here's what I would like this script to do:
: Run through a text file. Find all lines that are ALL CAPS and add
^^^^^^^^^^^^^^^^^^^^^^^
Or, to say it another way, lines that do not have any
lower case characters.
(blank lines or punctuation only lines will match below too...)
s!^!<H3>!, s!$!</H3>! unless /[a-z]/; # assuming $_ holds the 'line'
: something to them.
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 14 Oct 1997 01:33:58 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Reg expr. question (SEARCH and REPLACE)
Message-Id: <comdog-ya02408000R1410970133580001@news.panix.com>
In article <3442BB68.E1A738FC@qgraph.com>, Vinny Carpenter <vscarpenter@qgraph.com> wrote:
>Run through a text file. Find all lines that are ALL CAPS and add
>something to them.
>For example: If it encounters something like this:
>
>Before:
>
>ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU..
>
>After:
>
><H3>ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ..</H3>
does this work for you?
#!/usr/bin/perl -wT
while( $line = <DATA> )
{
$line =~ s| ^ ([A-Z\s]+) \n $ |<h2>$1</h2>\n|x;
print $line;
}
__DATA__
PERLRE(1) Perl Programmers Reference Guide PERLRE(1)
NAME
perlre - Perl regular expressions
DESCRIPTION
This page describes the syntax of regular expressions in
Perl. For a description of how to use regular expressions
in matching operations, plus various examples of the same,
see m// and s/// in the perlop manpage.
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Tue, 14 Oct 1997 01:36:15 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: uninitialized value warning for m// substrings
Message-Id: <comdog-ya02408000R1410970136150001@news.panix.com>
In article <61umlm$jtc$1@news2.cais.com>, systech@polarnet.com (Ken Irving) wrote:
you can turn warnings off and on by using $^W.
>#!/perl/bin/perl -w
{
local $^W = 0;
>if ( "123" =~ /(\d)(\d)(\d)?/g ) { print $1,$2,$3,"\n" };
>if ( "12" =~ /(\d)(\d)(\d)?/g ) { print $1,$2,$3,"\n" };
}
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: 14 Oct 1997 05:43:51 GMT
From: d-lewart@uiuc.edu (Daniel S. Lewart)
Subject: Re: uninitialized value warning for m// substrings
Message-Id: <61v0qn$7m1$1@vixen.cso.uiuc.edu>
systech@polarnet.com (Ken Irving) writes:
> I was hoping this would go away with 5.004_02, but the following
> sample code gives a warning if one of the substring arguments in
> the match is missing, because it is then used anyway. The warning
> is true, an uninitialized value is being used, but I know it will be
> null, and the result is useful and convenient. Perhaps this is a
> lousy technique which I've used to good effect, but is there a way
> to do this sort of thing without getting a warning?
> #!/perl/bin/perl -w
> if ( "123" =~ /(\d)(\d)(\d)?/g ) { print $1,$2,$3,"\n" };
> if ( "12" =~ /(\d)(\d)(\d)?/g ) { print $1,$2,$3,"\n" };
Yes; this:
print "$1\n" if "123" =~ /(\d\d\d?)/;
print "$1\n" if "12" =~ /(\d\d\d?)/;
or this:
print "$1\n" if "123" =~ /(\d{2,3})/;
print "$1\n" if "12" =~ /(\d{2,3})/;
Daniel Lewart
d-lewart@uiuc.edu
------------------------------
Date: 14 Oct 1997 03:55:02 GMT
From: kivisild@rs1.tcs.tulane.edu (James A. Kivisild)
Subject: Writing/Reading Binary Files
Message-Id: <61uqem$fmq$1@rs10.tcs.tulane.edu>
I'm trying to read and write to a binary file using a perl script.
I'd like to do the same thing as fread() in C where the file opened is a binary file...
(opened with fopen("file","rb"))
I've tried using read() but it simply reads in the data "as is" not coverting
it out of binary form. Has anyone done something like this or know of a way
to accomplish this?
In addition, I'd like to know how to write data to a binary file .
Thanks
-James
------------------------------
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 1172
**************************************