[18811] in Perl-Users-Digest
Perl-Users Digest, Issue: 979 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 24 18:11:00 2001
Date: Thu, 24 May 2001 15:10:26 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <990742225-v10-i979@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 24 May 2001 Volume: 10 Number: 979
Today's topics:
Re: Match Parsing Glitch <mischief@velma.motion.net>
Re: Match Parsing Glitch <nospam@xx.com>
Re: Match Parsing Glitch <nospam@xx.com>
Re: Match Parsing Glitch <nospam@xx.com>
Re: Match Parsing Glitch (E.Chang)
Re: need regex help please <gfbozzetti@interfree.it>
Re: parsing perl again (Jordan Dimov)
Re: parsing perl again (Damian Conway)
Re: Permuting days of the week <mischief@velma.motion.net>
Re: Q: about combining lines of a call record file... <mischief@velma.motion.net>
Re: read jpg newsgroup file <steve@peachy.com>
Re: read jpg newsgroup file <gerard@NOSPAMlanois.com>
Re: realpath(), abs_path() <postmaster@god.edu>
Re: realpath(), abs_path() <postmaster@god.edu>
Re: Recognize a number <gfbozzetti@interfree.it>
Re: Search and replace text in a file based on a specif <michael@heiming.de>
Re: Search and replace text in a file based on a specif <uri@sysarch.com>
Re: Search and replace text in a file based on a specif <michael@heiming.de>
Re: Search and replace text in a file based on a specif <uri@sysarch.com>
Re: Search and replace text in a file based on a specif <drobert@caissepop.mb.ca>
Re: Search and replace text in a file based on a specif <drobert@caissepop.mb.ca>
Re: Search and replace text in a file based on a specif <michael@heiming.de>
Re: sounder <todd@designsouth.net>
Re: sounder <todd@designsouth.net>
Re: sounder <todd@designsouth.net>
Re: This String Formation does not work properly, pleaz <ren@tivoli.com>
Re: url parsing (Charles DeRykus)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 24 May 2001 18:41:14 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Match Parsing Glitch
Message-Id: <tgqleap3sret5b@corp.supernews.com>
Eric <nospam@xx.com> wrote:
> Tad McClellan wrote:
>> Eric <nospam@xx.com> wrote:
>> >5.003_07 which I must use as is
>> If you stick with that version, then you will need to be a better
>> programmer than if you upgrade, because you will not be able to
>> reuse OPC without these backward-version "repairs". If you show
>> up here often trying to get help with such an endeavor, the
>> readership of your articles will decline.
> Tnx for all the tips. I was out-of-perl for the past 2 years, but
> downloaded build 626 however am having difficulty getting it installed.
> If I am "RTFM" (readme) it looks like I need to buy a compiler??? I
> don't recall having to do this to install what I do have (On my WIN32
> machine). Confusing.
You needn't compile Perl on Windows. ActiveState distributes as
executable (hence the words "_build_ 626". The README to which
you refer may be the standard README included with the source.
I have build 623 here, though, and I don't see such a beast.
If you were to _want_ to compile something in C or C++ on
Windows, you still don't need to _buy_ a compiler. Microsoft
doesn't rule the world, and there are other sources of software,
some of them entirely free of charge. Search on the web for
'DJGPP' and 'Cygwin'. You might also find Micro-C (a low-cost
but fairly nice commercial C compiler), or you could probably
still find the PCC port for DOS somewhere (but don't _use_
that... it's K&R). I'd recommend Cygwin or DJGPP.
Chris
--
Parking for people we like only. All other vehicles will be vandalized.
------------------------------
Date: Thu, 24 May 2001 11:56:00 -0700
From: Eric <nospam@xx.com>
Subject: Re: Match Parsing Glitch
Message-Id: <3B0D5940.F4715312@xx.com>
Chris Stith wrote:
>
> You needn't compile Perl on Windows. ActiveState distributes as
> executable (hence the words "_build_ 626". The README to which
> you refer may be the standard README included with the source.
> I have build 623 here, though, and I don't see such a beast.
>
Chris -
Tnx for the note. Are you saying I do NOT need to compile...and just
stick a path statement into my autoexec.bat file??? The "FM" readme is
not very clear if one just wants to download and use on a WIN32 machine
standalone. I just can't remember how in the heck I did it last time.
Eric
------------------------------
Date: Thu, 24 May 2001 12:01:22 -0700
From: Eric <nospam@xx.com>
Subject: Re: Match Parsing Glitch
Message-Id: <3B0D5A82.584E57C4@xx.com>
Abe Timmerman wrote:
> > # OBJECTIVES TO PARSE, CAPTURE & WRITE TO ASCII .csv FILE
> > # 4. SA (17 characters ... on 2nd line following "SA:"
> > # 5. LA (17 characters) ... on 12th line following "LA:"
>
> Are 4. and 5. _always_ true?
Abe -
Tnx for your insightful reply. By "always_ true?" ... to you mean will
there ALWAYS be something in those spaces??? I'd have to say 99.7%
"always".
>
> Why don't you use a "next unless" construct? There seems to be nothing
> outside this if construct (within the loop).
Duh on me...didn't think of this in the late night hour I guess ;0(
> Why do you want the output file to be reopened and closed for every
> write?
Good question...it's just the way I had the predecessor script work.
I'll try your kind suggestions and see what happens.
Eric
------------------------------
Date: Thu, 24 May 2001 14:05:13 -0700
From: Eric <nospam@xx.com>
Subject: Re: Match Parsing Glitch
Message-Id: <3B0D7788.74222C8F@xx.com>
Abe Timmerman wrote:
>
> Please, in future, use Copy/Paste if you want to show code here. People
> can't see the difference between typo's and other mistakes.
>
Abe -
OK...I plugged in your suggestions and have been scratching my head
trying to figure out what's wrong. I consolidated (hand-typed) the
error messages and perhaps you can help me decipher what's wrong. I #'d
out the whole "for 3..12" at Line 27 but that didn't work. I thought
more about your other question and "Yes"...each record will ALWAYS have
those lines which beging with 'SO' and/or 'LA' ... just the actual name
fields could be blank once in a while so no biggie there.
Eric
----
ERRORS:
Global symbol "R" requires specific package name at Line 3
Global symbol filename require specific package name at Lines 5,8,9
Global symbol datafile require specific package name at Line 7
Variable "$filename" is not imported at Line 8,9
Variable "$line" is not imported at Lines 17,21,23,25,28
Global symbol "line" require specific package name at Lines
14,17,21,23,25,28
syntax error at Line 28, near "<INPUT> for "
CODE PORTION:
while ( my $line = <INPUT> )
{
next unless $line =~ /^#\d{6}/; #Line 13
my( $status, $addr, $price ) =
unpack 'x13 A1 x2 A25 x28 A10', $line; #Line 16
$price =~ tr/$,//d;
$addr =~ s/^\s+//g; #trailing spaces removed by unpack 'A'
$line = <INPUT>; #This line should start with 'SO'
die "Line 2 of record didn't start with 'SO'\n"
unless $line =~ /^SO/; #Line 22
my( $sa ) = unpack 'x18 A17', $line; #Line 24
$sa =~ s/^\s+//g;
$line = <INPUT> for 3..12; # skip some lines
die "Line 12 of record didn't start with 'LA'\n"
unless $line =~ /^LA/; #Line 29
my( $la ) = unpack 'x3 A17', $line; #Line 31
$la =~ s/^\s+//g; #Line 32
writedatafile( $status, $addr, $price, $sa, $la ); #Line 34
}
close (INFILE); #close input file #Line 37
------------------------------
Date: Thu, 24 May 2001 21:18:10 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Match Parsing Glitch
Message-Id: <Xns90ABB0770A80Aechangnetstormnet@207.106.92.86>
Eric <nospam@xx.com> wrote in <3B0D5940.F4715312@xx.com>:
>Chris Stith wrote:
>>
>> You needn't compile Perl on Windows. ActiveState distributes as
>> executable (hence the words "_build_ 626". The README to which
>> you refer may be the standard README included with the source.
>> I have build 623 here, though, and I don't see such a beast.
>>
>Chris -
>
>Tnx for the note. Are you saying I do NOT need to compile...and
>just stick a path statement into my autoexec.bat file??? The "FM"
>readme is not very clear if one just wants to download and use on a
>WIN32 machine standalone. I just can't remember how in the heck I
>did it last time.
>
>Eric
You probably downloaded the "Build 626 Source Distribution" instead of
the already compiled version. The links on the ActiveState site are
side by side. Look again at
http://aspn.activestate.com/ASPN/Downloads/ActivePerl/. You want to
download from the ActivePerl 5.6.1.626 table on the left.
--
EBC
------------------------------
Date: Thu, 24 May 2001 20:41:47 +0200
From: GianFranco Bozzetti <gfbozzetti@interfree.it>
Subject: Re: need regex help please
Message-Id: <3B0D55EB.B231C2B0@interfree.it>
Merlin wrote:
>
> I have an expression here,
> expires_on => 'xpires\s+(.*?)\s*\n'
> that works fine, and returns the string correctly where the record
> contains;
> Expires on.......: May 22, 2001
>
> Is it possible to modify this expression so that it finds _either_ 'xpires'
> or 'xpiry' ??? or maybe even finds any string with just the 'xpir' in it?
>
> Thanks for any help,
> Robert
Try:
$s1 = "Expires May 21, 2001";
$s2 = "xpires May 22, 2001";
$s3 = "xpir May 23, 2001";
print "Expires on: $1\n" if $s1 =~ m'[Ee]?xpir[es]*\s+(.*)\s*';
print "Expires on: $1\n" if $s2 =~ m'[Ee]?xpir[es]*\s+(.*)\s*';
print "Expires on: $1\n" if $s3 =~ m'[Er]?xpir[es]*\s+(.*)\s*';
HTH
------------------------------
Date: 24 May 2001 13:50:20 -0700
From: jdimov@cis.clarion.edu (Jordan Dimov)
Subject: Re: parsing perl again
Message-Id: <7447a59a.0105241250.bd718b0@posting.google.com>
Thank you, Damian. Would appreciate a notice when you get to that point of
The ToDo List :-)
-- Jordan
P.S. I take it this implies your belief that RecDescent is capable of
performing the monsterous task?
damian@cs.monash.edu.au (Damian Conway) wrote in message news:<9eh8hu$v2f$1@towncrier.cc.monash.edu.au>...
> jdimov@cis.clarion.edu (Jordan Dimov) writes:
>
> > I think I've heard rummors that there's a Perl 5 grammar for Damian's
> > Parse::RecDescent?
>
> Not yet. It's high on the ToDo list, but not yet at the top.
>
> Meanwhile, you might want to take a peak inside Text::Balanced (particularly
> the C<extract_codeblock> subroutine). You might find you can adapt the code
> to your needs.
>
> Damian
------------------------------
Date: 24 May 2001 21:03:49 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: parsing perl again
Message-Id: <9ejsvl$jrn$1@towncrier.cc.monash.edu.au>
jdimov@cis.clarion.edu (Jordan Dimov) writes:
>Thank you, Damian. Would appreciate a notice when you get to that point of
>The ToDo List :-)
I'm sure it will be loudly heralded ;-)
>P.S. I take it this implies your belief that RecDescent is capable of
>performing the monsterous task?
Not as it stands. But a new version of RecDescent is also on the ToDo list!
Damian
------------------------------
Date: Thu, 24 May 2001 20:21:28 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Permuting days of the week
Message-Id: <tgqra85tbk9m5c@corp.supernews.com>
James Weisberg <chadbour@wwa.com> wrote:
> Here's a simple challenge.
>
> Given the days of the week: Sun, Mon, Tue, Wed, Thu, Fri, Sat
> I would like to take various permuations and sequences of those strings
> and fill the days in between. Examples:
> Sun-Sat = "Sun,Mon,Tue,Wed,Thu,Fri,Sat"
> Mon-Sun = "Mon,Tue,Wed,Thu,Fri,Sat,Sun"
> Wed-Tue = "Wed,Thu,Fri,Sat,Sun,Mon,Tue"
> etc, and sub-sequences:
> Sun-Tue = "Sun,Mon,Tue"
> Fri-Sun = "Fri,Sat,Sun"
> etc.
> So a function like fill($from, $to) would fill up to seven days
> $from - $to and $from != $to so Mon-Mon, for example, is invalid.
> Is there a clever solution for this?
Since the problem isn't so difficult, I decided to make it clear
just how helpful whitespace can be when programming in Perl. The
following is not obfuscated at all -- it just had its whitespace
stripped...
my%dow_name=('Sun'=>0,'Mon'=>1,'Tue'=>2,'Wed'=>3,'Thu'=>4,'Fri'=>5,
'Sat'=>6);my@dow_num=('Sun','Mon','Tue','Wed','Thu','Fri','Sat');my
@dow_list;if($dow_name{$ARGV[1]}<$dow_name{$ARGV[0]}){@dow_list=
@dow_num[$dow_name{$ARGV[0]}..6];push(@dow_list,@dow_num[0..
$dow_name{$ARGV[1]}]);}else{@dow_list=@dow_num[$dow_name{$ARGV[0]}..
$dow_name{$ARGV[1]}];}print join(',',@dow_list),"\n";
Now, if you can make that out without looking at it carefully,
let me know so I don't ever take a job maintaining your code.
It's not too difficult to follow, but it sure could be easier.
BTW, I promise it runs under strictures and warnings.
Chris
--
Try not. Do, or do not. The Force is binary. -- Yoda,
The Empire Strikes Back (paraphrased)
------------------------------
Date: Thu, 24 May 2001 20:55:38 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Q: about combining lines of a call record file...
Message-Id: <tgqtaalf5u4nb8@corp.supernews.com>
Todd Nathan <tnathan@midwayisland.net> wrote:
> Hi,
Hello!
> How would i write a Perl script to combine the lines of a Call Record
> into one line...? Thanks, and you are welcome to get a hold of me
> directly, I really appreciate your help!!!
Some other suggestions have been posted, but if your data shown
below is how the input actually looks, I can give you something
simple and fairly efficient.
while(<DATA>) {
chomp;
/^CR \d+:/ ? print "\n$_" : print;
}
print "\n";
__DATA__
CR 16178: CallType 1 04-MAY-2001 Disc-202
Seize 13:59:16 Ans 13:59:27 Disc 13:59:38 TS 0
A Party: MOBILE (11) 8084213370 Serial ed8283c4
0013(51: 2) 13:59:16[ 1]--13:59:38[ 1]
B Party: MOBILE (11) 8084213400 Serial fc097b20
0012(51: 1) 13:59:19[ 2]--13:59:38[ 1]
CR 16194: CallType 1 04-MAY-2001 Disc-202
Seize 13:59:26 Ans 13:59:34 Disc 13:59:43 TS 0
A Party: MOBILE (11) 8084213456 Serial e0da83ea
0024(51:11) 13:59:26[ 1]--13:59:43[ 1]
B Party: MOBILE (11) 8084213386 Serial 874a563a
0021(51: 8) 13:59:28[ 2]--13:59:43[ 1]
CR 16162: CallType 1 04-MAY-2001 Disc-203
Seize 13:59:12 Ans 13:59:53 Disc 13:59:53 TS 36
A Party: MOBILE (11) 8084213373 Serial 7713298a
0023(51:10) 13:59:12[ 1]--13:59:53[ 1]
B Party: PSTN (31) 9337
1091(36: 2) 13:59:14[ 4]--13:59:53[ 1]
Hope this helps,
Chris
--
Try not. Do, or do not. The Force is binary. -- Yoda,
The Empire Strikes Back (paraphrased)
------------------------------
Date: Thu, 24 May 2001 21:03:30 +0100
From: "Steve Kay" <steve@peachy.com>
Subject: Re: read jpg newsgroup file
Message-Id: <9ejph7$j2e$1@uranium.btinternet.com>
Wonder if the Convert-UU module will do the trick?
http://testers.cpan.org/search?request=dist;dist=Convert-UU
SYNOPSIS
use Convert::UU qw(uudecode uuencode);
$encoded_string = uuencode($string,[$filename],[$mode]);
($string,$filename,$mode) = uudecode($string);
$string = uudecode($string); # in scalar context
DESCRIPTION
uuencode() takes as the first argument a string that is to be
uuencoded. Note, that it is the string that is encoded, not a
filename. Alternatively a filehandle may be passed that must be
opened for reading. It returns the uuencoded string including
`begin' and `end'. Second and third argument are optional and
specify filename and mode. If unspecified these default to
"uuencode.uu" and 644.
"mk" <N@b.COM> wrote in message
news:5l8P6.4658$%X5.1442600@typhoon1.ba-dsg.net...
> I am trying to use perl to download jpgs from usenet. I've been using
> Net::NNTP on a W32 machine and have hit a snag. most of these messages
seem
> to be in the format:
>
> BEGIN picturename.jpg
> ...many lines of junk that Outlook automatically translates into image...
> END
>
> Any help would be greatly appreciated. Thanks in advance. I assure you
> that I am using this for good.
>
> -Mike
>
>
------------------------------
Date: 24 May 2001 14:12:58 -0700
From: Gerard Lanois <gerard@NOSPAMlanois.com>
Subject: Re: read jpg newsgroup file
Message-Id: <u4ruawiw5.fsf@NOSPAMlanois.com>
"Steve Kay" <steve@peachy.com> writes:
> Wonder if the Convert-UU module will do the trick?
>
> http://testers.cpan.org/search?request=dist;dist=Convert-UU
>
I've always been partial to this one:
http://language.perl.com/ppt/src/uudecode/uudecode.nick
-Gerard
http://www.lanois.com/perl/
------------------------------
Date: Thu, 24 May 2001 11:19:58 -0700
From: /dev/null <postmaster@god.edu>
Subject: Re: realpath(), abs_path()
Message-Id: <3B0D50CE.95047F23@god.edu>
On 24 May 2001, at 09:17:21 GMT, Anno Siegel wrote:
> The rel2abs() function in File::Spec doesn't have this limitation.
> Cwd is explicitly designed to deal with directories.
Thanks, Anno! But I'm not quite where I want to be yet...
Here is what I'm looking for: a perl function that does what
realpath(3) does. From the realpath(3) man page:
REALPATH(3) Linux Programmer's Manual REALPATH(3)
NAME
realpath - return the canonicalized absolute pathname
SYNOPSIS
#include <limits.h>
#include <stdlib.h>
char *realpath(const char *path, char *resolved_path);
DESCRIPTION
realpath expands all symbolic links and resolves refer=AD
ences to '/./', '/../' and extra '/' characters in the
null terminated string named by path and stores the canon=AD
icalized absolute pathname in the buffer of size PATH_MAX
named by resolved_path. The resulting path will have no
symbolic link, '/./' or '/../' components.
Unfortunately, rel2abs() doesn't seem to resolve the symlinks. My test
program output is:
Current directory: /home/extasia
Given path: tmp/junk.d/hosts.l
Contents of symlink tmp/junk.d/hosts.l: /etc/hosts
Return value from rel2abs( $path ): =
/home/extasia/tmp/junk.d/hosts.l
Return value from realpath(3) /etc/hosts
Whereas realpath(3) does resolve symlinks.
The test program is:
#!/usr/bin/perl -w
use strict;
use File::Spec::Unix;
my $path =3D "tmp/junk.d/hosts.l";
printf "%-41s", "Current directory:";
system "pwd";
printf "%-41s%s\n", "Given path:", $path;
printf "%-41s%s\n", "Contents of symlink $path:", readlink $path;
printf "%-41s%s\n", "Return value from rel2abs( \$path ): ",
File::Spec::Unix->rel2abs( $path );
printf "%-41s", "Return value from realpath(3)";
system ( "$ENV{ HOME }/bin/realpath", $path );
$HOME/bin/realpath is a C wrapper I wrote around realpath(3):
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#define MAXLINELENGTH 1024
char *pgm;
=
/*--------------------------------------------------------------------*/
void usage( char *pgm ) {
fprintf( stderr, "usage: %s Path\n", pgm );
} /* usage() */
=
/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
main ( int argc, char **argv ) {
char *path, *resolved_path;
resolved_path =3D malloc( MAXLINELENGTH );
pgm =3D argv[ 0 ];
if ( argc !=3D 2 ) {
usage( pgm );
exit( 255 );
} /* if */
path =3D argv[ 1 ];
if (( resolved_path =3D realpath( path, resolved_path )) =3D=3D NULL =
) {
exit( 127 );
} /* if */
printf( "%s\n", resolved_path );
exit( 0 );
} /* main */
David
-- =
David Alban
extasia "@" mindspring "." com
Live in a world of your own, but always welcome visitors.
------------------------------
Date: Thu, 24 May 2001 11:44:22 -0700
From: /dev/null <postmaster@god.edu>
Subject: Re: realpath(), abs_path()
Message-Id: <3B0D5686.F27F5376@god.edu>
On 24 May 2001, at 17:55:46 +0100, nobull@mail.com wrote:
> Indeed it is, much more. It is also a big clue that what you are
> attempting to do is probably something you would probably be better
> off not doing.
I'm not sure why I'd be better off not wanting a perl function to
emulate realpath(3).
> In Unix unique absolute path as a concept only actually applies to
> directories.
Actually, an absolute canonicalized path (in unix) is one in which:
a. It begins with a slash ('/')
b. It contains no "." or ".." components
c. It contains no components which are symbolic links
d. All occurrences of slashes are single slashes
I'm not sure whether 'd' is mandatory, but it is desired.
> Anyhow, you say "Did the authors not see value?". What do _you_ see
> as the value? Think carefully. I have in the past found myself
> instictively wanting (and even inplementing) your realpath() function
> (not just in Perl) and then realised, on refelction, that my instinct
> is wrong.
What I want to use it for is to determine whether or not two
different paths refer to the same file or directory. One option is
to compare the filesystem and inode of each candidate. Another is to
determine the absolute canonicalized paths of each and see if they
are the same.
> > If not, should I submit my realpath() function?
>
> I think you should show it here first.
O.K. I'll need to clean it up first.
David
--
David Alban
extasia "@" mindspring "." com
Live in a world of your own, but always welcome visitors.
------------------------------
Date: Thu, 24 May 2001 20:50:09 +0200
From: GianFranco Bozzetti <gfbozzetti@interfree.it>
Subject: Re: Recognize a number
Message-Id: <3B0D57E1.5333773@interfree.it>
Tim Lauterborn wrote:
>
> Hi,
>
> I am looking for a regular expression that recognizes numbers. If they have
> a trailing + or - they should be accepted too.
>
> For example:
> accepted:
> 20
> +20
> -20
> ...
>
> not accepted:
> 20a
> b20
> --20
> ...
>
> Thanks!
>
> Greetings,
> Tim
Try:
$str="-123a";
print "$str is Not a number\n" if ($str =~ m/[^0-9+-]+/);
$str = "123-";
print "$str is a number\n" if ($str =~ m/[0-9+-]+/);
$str = "+123";
print "$str is a number\n" if ($str =~ m/[0-9+-]+/);
HTH
------------------------------
Date: Thu, 24 May 2001 20:31:56 +0200
From: Michael Heiming <michael@heiming.de>
Subject: Re: Search and replace text in a file based on a specific line
Message-Id: <3B0D539C.932BF57A@heiming.de>
Daniel Robert wrote:
>
> Upon looking at it carefully, I noticed that the file does not get modified.
> The original file must containt the original lines but with the changes we
> specified. This is where I had difficulty to start with.
You didn't not mentioned this in your original post. Now I would use
awk:
awk '{if ($0 ~ /line\ 6/) ((o=$0) && sub ("test\ \#..","test\
\#www",$0) && ($0=$0" "o))} {print $0 }' testfile > testfile2
This is all on one line.
Michael Heiming
[SNIP]
------------------------------
Date: Thu, 24 May 2001 19:00:19 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Search and replace text in a file based on a specific line
Message-Id: <x77kz64loe.fsf@home.sysarch.com>
>>>>> "MH" == Michael Heiming <michael@heiming.de> writes:
MH> You didn't not mentioned this in your original post. Now I would use
MH> awk:
MH> awk '{if ($0 ~ /line\ 6/) ((o=$0) && sub ("test\ \#..","test\
MH> \#www",$0) && ($0=$0" "o))} {print $0 }' testfile > testfile2
gack!! that is more unreadable than some of the worst perl i have ever
seen.
let perl do most of the work for you.
perl -pe '/line 6/ && s/test #../test #www/'
or to make it handle command line args:
perl -pe '/$ARGV[0]/ && s/$ARGV[1]/$ARGV[2]/' 'line 6' 'test #..' 'test #www'
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Thu, 24 May 2001 21:40:17 +0200
From: Michael Heiming <michael@heiming.de>
Subject: Re: Search and replace text in a file based on a specific line
Message-Id: <3B0D63A1.41CD774@heiming.de>
Uri Guttman wrote:
>
> >>>>> "MH" == Michael Heiming <michael@heiming.de> writes:
>
> MH> You didn't not mentioned this in your original post. Now I would use
> MH> awk:
>
> MH> awk '{if ($0 ~ /line\ 6/) ((o=$0) && sub ("test\ \#..","test\
> MH> \#www",$0) && ($0=$0" "o))} {print $0 }' testfile > testfile2
>
> gack!! that is more unreadable than some of the worst perl i have ever
> seen.
Sure it looks strange, but it does a bit more then the line perl you
suggested.
Regards
Michael Heiming
> let perl do most of the work for you.
>
> perl -pe '/line 6/ && s/test #../test #www/'
>
> or to make it handle command line args:
>
> perl -pe '/$ARGV[0]/ && s/$ARGV[1]/$ARGV[2]/' 'line 6' 'test #..' 'test #www'
>
> uri
>
> --
> Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
------------------------------
Date: Thu, 24 May 2001 20:43:34 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Search and replace text in a file based on a specific line
Message-Id: <x71ype4gwa.fsf@home.sysarch.com>
>>>>> "MH" == Michael Heiming <michael@heiming.de> writes:
MH> Uri Guttman wrote:
>>
>> >>>>> "MH" == Michael Heiming <michael@heiming.de> writes:
>>
MH> You didn't not mentioned this in your original post. Now I would use
MH> awk:
>>
MH> awk '{if ($0 ~ /line\ 6/) ((o=$0) && sub ("test\ \#..","test\
MH> \#www",$0) && ($0=$0" "o))} {print $0 }' testfile > testfile2
>>
>> gack!! that is more unreadable than some of the worst perl i have ever
>> seen.
MH> Sure it looks strange, but it does a bit more then the line perl you
MH> suggested.
i was following the OP request. you seem to keep the original line
around as well. the problem was not very well specified. if you give me
tighter specs, i could easily change the code to handle it.
i used to be an awk guru, but that was many generations ago. awk has
almost no need to live anymore.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Thu, 24 May 2001 15:42:31 -0500
From: "Daniel Robert" <drobert@caissepop.mb.ca>
Subject: Re: Search and replace text in a file based on a specific line
Message-Id: <XqeP6.3707$gg2.39410@news1.mts.net>
This is what I meant by "replace"... which would actually do a search and
replace in the file.
"Michael Heiming" <michael@heiming.de> wrote in message
news:3B0D539C.932BF57A@heiming.de...
> Daniel Robert wrote:
> >
> > Upon looking at it carefully, I noticed that the file does not get
modified.
> > The original file must containt the original lines but with the changes
we
> > specified. This is where I had difficulty to start with.
>
> You didn't not mentioned this in your original post. Now I would use
> awk:
>
> awk '{if ($0 ~ /line\ 6/) ((o=$0) && sub ("test\ \#..","test\
> \#www",$0) && ($0=$0" "o))} {print $0 }' testfile > testfile2
>
> This is all on one line.
>
> Michael Heiming
>
> [SNIP]
------------------------------
Date: Thu, 24 May 2001 16:35:54 -0500
From: "Daniel Robert" <drobert@caissepop.mb.ca>
Subject: Re: Search and replace text in a file based on a specific line
Message-Id: <%cfP6.3715$gg2.39530@news1.mts.net>
I am sorry if I didn't express myself very well, but here goes again...
I want to create a sh script which will search a text file (parameter 1) for
a specific string (parameter 2). This is used to uniquely identify exactly
which line I need modify. The next step is to replace FROM text that is
supplied (parameter 3) (it can contain one or more "?" (or none) as a
wildcard) TO text that is also supplied (parameter 4). So the format would
be:
replinfile textfile searchtext replacefrom replaceto
where textfile = text file to search and replace
searchtext = the initial text to search for (used to uniquely
identify the line because the replace is done ONLY on one line)
replacefrom = the text which identifies what text must be replaced
(the "?" can be used as a wildcard)
replaceto = what the text must be replace with.
So if I had a text file called testfile which had a line "Oh no. Here we go
now." (among other lines) and used my sh script with the following:
replinfile testfile "Oh no." "now." "again!"
I would have the line replaced in the file testfile to "Oh no. Here we go
again!"
I hope I have provided enough information and made myself clear. ;)
PS I have tried the awk solution and, as mentionned it repeats th line in
the file. I have also tried the perl solution and I get the errors "Can't
open line 6: No such file or directory", "Can't open test #..: No such file
or directory", and "Can't open test #www: No such file or directory".
Shouldn't you need to specify the name of the file somewhere? I don't even
remotely know perl (only know of it) but I forsee the need to delve in it in
the future.
"Uri Guttman" <uri@sysarch.com> wrote in message
news:x71ype4gwa.fsf@home.sysarch.com...
> >>>>> "MH" == Michael Heiming <michael@heiming.de> writes:
>
> MH> Uri Guttman wrote:
> >>
> >> >>>>> "MH" == Michael Heiming <michael@heiming.de> writes:
> >>
> MH> You didn't not mentioned this in your original post. Now I would use
> MH> awk:
> >>
> MH> awk '{if ($0 ~ /line\ 6/) ((o=$0) && sub ("test\ \#..","test\
> MH> \#www",$0) && ($0=$0" "o))} {print $0 }' testfile > testfile2
> >>
> >> gack!! that is more unreadable than some of the worst perl i have
ever
> >> seen.
>
> MH> Sure it looks strange, but it does a bit more then the line perl you
> MH> suggested.
>
> i was following the OP request. you seem to keep the original line
> around as well. the problem was not very well specified. if you give me
> tighter specs, i could easily change the code to handle it.
>
> i used to be an awk guru, but that was many generations ago. awk has
> almost no need to live anymore.
>
> uri
>
> --
> Uri Guttman --------- uri@sysarch.com ----------
http://www.sysarch.com
> SYStems ARCHitecture and Stem Development ------
http://www.stemsystems.com
> Learn Advanced Object Oriented Perl from Damian Conway - Boston, July
10-11
> Class and Registration info:
http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Fri, 25 May 2001 00:00:37 +0200
From: Michael Heiming <michael@heiming.de>
Subject: Re: Search and replace text in a file based on a specific line
Message-Id: <3B0D8485.D6D9375A@heiming.de>
Daniel Robert wrote:
[SNIP]
>
> PS I have tried the awk solution and, as mentionned it repeats th line in
> the file.
Err. it repeats what? You wrote:
"The original file must containt the original lines but with the changes
we
specified." ^^^^^^^^^^^^^^^^^^^^
That's exactly what the line awk does, I posted...
Michael Heiming
[SNIP]
> > >>
> > >> >>>>> "MH" == Michael Heiming <michael@heiming.de> writes:
> > >>
> > MH> You didn't not mentioned this in your original post. Now I would use
> > MH> awk:
> > >>
> > MH> awk '{if ($0 ~ /line\ 6/) ((o=$0) && sub ("test\ \#..","test\
> > MH> \#www",$0) && ($0=$0" "o))} {print $0 }' testfile > testfile2
[SNIP]
------------------------------
Date: Thu, 24 May 2001 20:38:06 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: sounder
Message-Id: <OieP6.66921$I5.14182438@news1.rdc1.tn.home.com>
> > Well, since Perl is the only cgi language I know, I'd like to see the
Perl
> > implementation of the complete solution.
> >
> > -todd
>
> You can use nearly any computer language for CGI's.
>
> Buggs
i COULD, but not without learning them first. I'm a perl guy.
------------------------------
Date: Thu, 24 May 2001 20:41:00 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: sounder
Message-Id: <wleP6.66935$I5.14183418@news1.rdc1.tn.home.com>
> if you want help, explain what you mean by
> "user signs up",
Oh Tina, you know- If I'm selling a service and a person registers for it,
or I'm selling a product and their account online, or I'm giving something
away, and they "sign up" for it. You know.
> "the page is asked to beep".
beep, like, make a noise?
page- the page my browser is on?
and you might want to
> do that in the appropriate newsgroup for cgi. for certain
> perl questions, you are welcome to ask here.
Oh Tina, those guys in the cgi group suck. You people are much more
intelligent.
-todd
------------------------------
Date: Thu, 24 May 2001 20:41:23 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: sounder
Message-Id: <TleP6.66938$I5.14184271@news1.rdc1.tn.home.com>
"Thorbjørn Ravn Andersen" <thunderbear@bigfoot.com> wrote in message
news:3B0D3A50.3B067706@bigfoot.com...
> Todd Smith wrote:
>
> > Well, since Perl is the only cgi language I know, I'd like to see the
Perl
> > implementation of the complete solution.
>
> Hack the "user sign up" script to send you an email.
>
Emails are boring! I want noise!
------------------------------
Date: 24 May 2001 14:32:17 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: This String Formation does not work properly, pleaze help!
Message-Id: <m3ofsibl1a.fsf@dhcp9-172.support.tivoli.com>
On Wed, 23 May 2001, Lars.Plessmann@gmx.de wrote:
> I changed, but it does not cut after the dot. Not I get numbers like
> 132,2898430840 but it should be 132,29 then.
>
> sub MoneyFormat
> {
> # rounding the currency
> $_=sprintf("%.02f", $_);
Here you're rounding before you get the value.
> # currency format adding commas for easy read
> my $buf=0;
You aren't using $buf....
> local $_ = shift;
Here you're getting the value. You need to move the sprintf line from
above to here.
> 1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
>
> # Change dots to comma and comma to dots (German form)
> tr/,./.,/;
>
> return $_;
> }
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 24 May 2001 18:06:13 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: url parsing
Message-Id: <GDuqAD.Jv6@news.boeing.com>
In article <3B0C635E.B7040473@earthlink.net>,
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
>Craig Berry wrote:
>>
>> Patrick Joyce (joycefive@earthlink.net) wrote:
>> : I need a program that takes a url and strips out everything but the
>> : domain this would normally not be as hard but i need this to work
>> : for such urls as ".com.au, .co.jp" and "foo.me.com, hi.test.you.com"
>> : so if my url was http://www.tiac/net/users/candvr then i would only
>> : want tiac.net.
>>
>> One way, assuming vanilla http urls:
>>
>> ($domain) = $url =~ m!//(.*?)/!;
>
>But that doesn't work if the string is, eg, "http://www.tiac.net" with
>no trailing slash. Here is an untested regex which should work for all
>valid urls.
>
> ($proto, $domain, $path) = $url =~ m[
> (\w+) : (?://([^/\s]*))? (\S*) ]x;
>
>This should work ok with any of:
> proto://host/path
> proto://host/
> proto://host
> proto:///path
> proto:path
>
>The last two forms are common for file urls (file:///usr/local/... or
>file:/usr/local/...) and the last is common for news urls
>(news:comp.lang.perl.misc). Path will include a leading slash, if one
>is there. Host does *not* include the leading // if it is there.
The URI module makes this quite a bit easier:
perl -MURI -le 'print URI->new("http://www.tiac.net")->host'
www.tiac.net
perl -MURI -le 'print URI->new("http://www.tiac/net/users/candvr")->host'
www.tiac
--
Charles DeRykus
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 979
**************************************