[16827] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4239 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 6 18:10:44 2000

Date: Wed, 6 Sep 2000 15:10:29 -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: <968278229-v9-i4239@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 6 Sep 2000     Volume: 9 Number: 4239

Today's topics:
        golf: remove .txt from filenames <matt.stoker@motorola.com>
    Re: golf: remove .txt from filenames <stephenk@cc.gatech.edu>
    Re: golf: remove .txt from filenames <calle@lysator.liu.se>
    Re: golf: remove .txt from filenames <lr@hpl.hp.com>
    Re: golf: remove .txt from filenames (Abigail)
    Re: golf: remove .txt from filenames <anmcguire@ce.mediaone.net>
    Re: golf: remove .txt from filenames <anmcguire@ce.mediaone.net>
    Re: golf: remove .txt from filenames <yanick@babyl.sympatico.ca>
    Re: golf: remove .txt from filenames <uri@sysarch.com>
    Re: golf: remove .txt from filenames <lr@hpl.hp.com>
    Re: golf: remove .txt from filenames <anmcguire@ce.mediaone.net>
    Re: golf: remove .txt from filenames (Smylers)
    Re: golf: remove .txt from filenames <matt.stoker@motorola.com>
    Re: golf: remove .txt from filenames (Smylers)
    Re: golf: remove .txt from filenames (Smylers)
    Re: golf: remove .txt from filenames <matt.stoker@motorola.com>
    Re: Good companion book to Programming Perl? (Mark-Jason Dominus)
        Help needed - regexp <andrew@innismaggiore.com>
    Re: Help needed - regexp <lr@hpl.hp.com>
    Re: Help needed - regexp <matt.stoker@motorola.com>
    Re: Help needed - regexp <zli@umr.edu>
    Re: Help needed - regexp <andrew@innismaggiore.com>
    Re: Help needed - regexp (David Wall)
    Re: Help needed - regexp <lr@hpl.hp.com>
        Help with Expect Perl Script <ygguh@aol.com>
    Re: Help with looping through code needed <lr@hpl.hp.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 06 Sep 2000 11:09:48 -0700
From: Matthew Stoker <matt.stoker@motorola.com>
Subject: golf: remove .txt from filenames
Message-Id: <39B6886C.763D12A@motorola.com>

Since windows has so generously appended .txt to all of my text data
files, I now need to strip the .txt from the filenames of all the files
in a given directory. After much trial and tribulation (mostly due to
omitting the chomp), I finally got this to work:

perl -e 'map {if (m/\.txt$/) {chomp;s/\.txt$//; rename "$_.txt","$_"}}
`ls`'

But, there has to be a better way.  Perl golf anyone?

-- 
/------------------------------------------------------------------\
| Matt Stoker                |     email: matt.stoker@motorola.com |
| Unit Process Modeling      | Mail Drop: M360                     |
| DigitalDNA(TM) Laboratories|     Phone: (480)655-3301            |
| Motorola, SPS              |       Fax: (480)655-5013            |
| 2200 W Broadway Road       |     Pager: (888)699-8803            |
| Mesa, AZ 85202             |                                     |
\------------------------------------------------------------------/


------------------------------

Date: Wed, 06 Sep 2000 15:09:55 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: golf: remove .txt from filenames
Message-Id: <39B69683.4B8C2F6D@cc.gatech.edu>

Matthew Stoker wrote:

> Since windows has so generously appended .txt to all of my text data
> files, I now need to strip the .txt from the filenames of all the files
> in a given directory. After much trial and tribulation (mostly due to
> omitting the chomp), I finally got this to work:
>
> perl -e 'map {if (m/\.txt$/) {chomp;s/\.txt$//; rename "$_.txt","$_"}}
> `ls`'
>
> But, there has to be a better way.  Perl golf anyone?
>

perl -e 'foreach(<*>) { next unless /^(.*)\.txt$/;rename $_,$1}'

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




------------------------------

Date: 06 Sep 2000 21:17:58 +0200
From: Calle Dybedahl <calle@lysator.liu.se>
Subject: Re: golf: remove .txt from filenames
Message-Id: <86pumhtjmh.fsf@tezcatlipoca.algonet.se>

>>>>> "Matthew" == Matthew Stoker <matt.stoker@motorola.com> writes:

> perl -e 'map {if (m/\.txt$/) {chomp;s/\.txt$//; rename "$_.txt","$_"}}
> `ls`'

> But, there has to be a better way.  Perl golf anyone?

perl -le 'for(<*.txt>){s/\.txt$//;rename"$_.txt",$_}'
-- 
 Calle Dybedahl, Vasav. 82, S-177 52 Jaerfaella,SWEDEN | calle@lysator.liu.se
  "Such a pretty day for a bloodbath." -- Callisto, "Xena: Warrior Princess"


------------------------------

Date: Wed, 6 Sep 2000 12:40:45 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: golf: remove .txt from filenames
Message-Id: <MPG.14203d934afc9d2b98ad2b@nntp.hpl.hp.com>

In article <39B69683.4B8C2F6D@cc.gatech.edu> on Wed, 06 Sep 2000 
15:09:55 -0400, Stephen Kloder <stephenk@cc.gatech.edu> says...
> Matthew Stoker wrote:
> 
> > Since windows has so generously appended .txt to all of my text data
> > files, I now need to strip the .txt from the filenames of all the files
> > in a given directory. After much trial and tribulation (mostly due to
> > omitting the chomp), I finally got this to work:
> >
> > perl -e 'map {if (m/\.txt$/) {chomp;s/\.txt$//; rename "$_.txt","$_"}}
> > `ls`'
> >
> > But, there has to be a better way.  Perl golf anyone?
> >
> 
> perl -e 'foreach(<*>) { next unless /^(.*)\.txt$/;rename $_,$1}'

Same way, but more compact:

  perl -e'/(.+)\.txt$/&&rename$_,$1for<*>'

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 06 Sep 2000 16:16:30 EDT
From: abigail@foad.org (Abigail)
Subject: Re: golf: remove .txt from filenames
Message-Id: <slrn8rd9f3.tjm.abigail@alexandra.foad.org>

Calle Dybedahl (calle@lysator.liu.se) wrote on MMDLXIII September
MCMXCIII in <URL:news:86pumhtjmh.fsf@tezcatlipoca.algonet.se>:
?? >>>>> "Matthew" == Matthew Stoker <matt.stoker@motorola.com> writes:
?? 
?? > perl -e 'map {if (m/\.txt$/) {chomp;s/\.txt$//; rename "$_.txt","$_"}}
?? > `ls`'
?? 
?? > But, there has to be a better way.  Perl golf anyone?
?? 
?? perl -le 'for(<*.txt>){s/\.txt$//;rename"$_.txt",$_}'

Saving 19 strokes:

   ls|perl -ne'/\.txt$/&&rename$_,$`'


Abigail
-- 
package Z;use overload'""'=>sub{$b++?Hacker:Another};
sub TIESCALAR{bless\my$y=>Z}sub FETCH{$a++?Perl:Just}
$,=$";my$x=tie+my$y=>Z;print$y,$x,$y,$x,"\n";#Abigail


------------------------------

Date: Wed, 6 Sep 2000 15:15:56 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: golf: remove .txt from filenames
Message-Id: <Pine.LNX.4.21.0009061459520.4007-100000@hawk.ce.mediaone.net>

On Wed, 6 Sep 2000, Stephen Kloder quoth:

~~ Date: Wed, 06 Sep 2000 15:09:55 -0400
~~ From: Stephen Kloder <stephenk@cc.gatech.edu>
~~ Newsgroups: comp.lang.perl.misc
~~ Subject: Re: golf: remove .txt from filenames
~~ 
~~ Matthew Stoker wrote:
~~ 
~~ > Since windows has so generously appended .txt to all of my text data
~~ > files, I now need to strip the .txt from the filenames of all the files
~~ > in a given directory. After much trial and tribulation (mostly due to
~~ > omitting the chomp), I finally got this to work:
~~ >
~~ > perl -e 'map {if (m/\.txt$/) {chomp;s/\.txt$//; rename "$_.txt","$_"}}
~~ > `ls`'
~~ >
~~ > But, there has to be a better way.  Perl golf anyone?
~~ >
~~ 
~~ perl -e 'foreach(<*>) { next unless /^(.*)\.txt$/;rename $_,$1}'

   perl -e'map{$f=$_;$/=".txt";chomp;rename$f,$_}<*>'
   perl -e'map{$f=$_;s,.txt$,,;rename$f,$_}<*>'

anm
-- 
Andrew N. McGuire
anmcguire@ce.mediaone.net
perl -le'print map?"(.*)"?&&($_=$1)&&s](\w+)]\u$1]g&&$_=>`perldoc -qj`'



------------------------------

Date: Wed, 6 Sep 2000 15:26:12 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: golf: remove .txt from filenames
Message-Id: <Pine.LNX.4.21.0009061519330.4007-100000@hawk.ce.mediaone.net>

On Wed, 6 Sep 2000, Andrew N. McGuire  quoth:

~~ Date: Wed, 6 Sep 2000 15:15:56 -0500
~~ From: Andrew N. McGuire  <anmcguire@ce.mediaone.net>
~~ Newsgroups: comp.lang.perl.misc
~~ Subject: Re: golf: remove .txt from filenames
~~ 
[ snip ]

~~    perl -e'map{$f=$_;$/=".txt";chomp;rename$f,$_}<*>'
~~    perl -e'map{$f=$_;s,.txt$,,;rename$f,$_}<*>'
~~ 
      perl -e'map{?(.*).txt$?;rename$&,$1}<*>'
anm
-- 
Andrew N. McGuire
anmcguire@ce.mediaone.net
perl -le'print map?"(.*)"?&&($_=$1)&&s](\w+)]\u$1]g&&$_=>`perldoc -qj`'



------------------------------

Date: Wed, 06 Sep 2000 20:29:55 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: golf: remove .txt from filenames
Message-Id: <7Pxt5.218532$Gh.4714561@news20.bellglobal.com>

Larry Rosler <lr@hpl.hp.com> wrote:
: In article <39B69683.4B8C2F6D@cc.gatech.edu> on Wed, 06 Sep 2000 
: 15:09:55 -0400, Stephen Kloder <stephenk@cc.gatech.edu> says...
:> Matthew Stoker wrote:
:> 
<snip>
:> > [..] I now need to strip the .txt from the filenames of all the files
:> > in a given directory. [..]
:> >
:> > perl -e 'map {if (m/\.txt$/) {chomp;s/\.txt$//; rename "$_.txt","$_"}}
:> > `ls`'
:> >
:> > But, there has to be a better way.  Perl golf anyone?
:> 
:> perl -e 'foreach(<*>) { next unless /^(.*)\.txt$/;rename $_,$1}'

: Same way, but more compact:

:   perl -e'/(.+)\.txt$/&&rename$_,$1for<*>'

	Same thing, with yet more juice squeezed out of it:

	 perl -e'/\.txt$/&&rename$_,$`for<*>'


Joy,
Yanick

-- 
$_= "e nte elhce.rka rPrhoatY";   @nothing = ( '', '' );
s#(.)(.*)(.)#$2#g and ($\,$,)=($1,$3) and print @nothing
while $_;


------------------------------

Date: Wed, 06 Sep 2000 20:31:01 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: golf: remove .txt from filenames
Message-Id: <x7n1hljm9m.fsf@home.sysarch.com>

>>>>> "A" == Abigail  <abigail@foad.org> writes:

  A>    ls|perl -ne'/\.txt$/&&rename$_,$`'

you forgot -l to chomp the \n from ls which is still in $_. but i like
the use of $`!

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


------------------------------

Date: Wed, 6 Sep 2000 13:42:15 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: golf: remove .txt from filenames
Message-Id: <MPG.14204c009a97805098ad2d@nntp.hpl.hp.com>

In article <slrn8rd9f3.tjm.abigail@alexandra.foad.org> on 06 Sep 2000 
16:16:30 EDT, Abigail <abigail@foad.org> says...
> Calle Dybedahl (calle@lysator.liu.se) wrote on MMDLXIII September
> MCMXCIII in <URL:news:86pumhtjmh.fsf@tezcatlipoca.algonet.se>:
> ?? >>>>> "Matthew" == Matthew Stoker <matt.stoker@motorola.com> writes:
> ?? 
> ?? > perl -e 'map {if (m/\.txt$/) {chomp;s/\.txt$//; rename "$_.txt","$_"}}
> ?? > `ls`'
> ?? 
> ?? > But, there has to be a better way.  Perl golf anyone?
> ?? 
> ?? perl -le 'for(<*.txt>){s/\.txt$//;rename"$_.txt",$_}'
> 
> Saving 19 strokes:
> 
>    ls|perl -ne'/\.txt$/&&rename$_,$`'

Drat.  Costs two more strokes to do it all in Perl.

     perl -e'/\.txt$/&&rename$_,$`for<*>'

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Wed, 6 Sep 2000 15:50:29 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: golf: remove .txt from filenames
Message-Id: <Pine.LNX.4.21.0009061547450.4025-100000@hawk.ce.mediaone.net>

On Wed, 6 Sep 2000, Andrew N. McGuire  quoth:

~~ Date: Wed, 6 Sep 2000 15:26:12 -0500
~~ From: Andrew N. McGuire  <anmcguire@ce.mediaone.net>
~~ Newsgroups: comp.lang.perl.misc
~~ Subject: Re: golf: remove .txt from filenames
~~ 
~~ On Wed, 6 Sep 2000, Andrew N. McGuire  quoth:
~~ 
~~ ~~ Date: Wed, 6 Sep 2000 15:15:56 -0500
~~ ~~ From: Andrew N. McGuire  <anmcguire@ce.mediaone.net>
~~ ~~ Newsgroups: comp.lang.perl.misc
~~ ~~ Subject: Re: golf: remove .txt from filenames
~~ ~~ 
~~ [ snip ]
~~ 
~~ ~~    perl -e'map{$f=$_;$/=".txt";chomp;rename$f,$_}<*>'
~~ ~~    perl -e'map{$f=$_;s,.txt$,,;rename$f,$_}<*>'
~~ ~~ 
~~       perl -e'map{?(.*).txt$?;rename$&,$1}<*>'

Oops, there I go again, make '.txt' '\.txt'.
Anything to save a stroke I guess. :-(

anm
-- 
Andrew N. McGuire
anmcguire@ce.mediaone.net
perl -le'print map?"(.*)"?&&($_=$1)&&s](\w+)]\u$1]g&&$_=>`perldoc -qj`'



------------------------------

Date: Wed, 6 Sep 2000 21:53:33 +0100 (BST)
From: Smylers-usenet@stripey.com (Smylers)
Subject: Re: golf: remove .txt from filenames
Message-Id: <2000Sep6.205334.27065@leeds.ac.uk>

Andrew N. McGuire  <anmcguire@ce.mediaone.net> uttered something along
the lines of:

> perl -e'map{$f=$_;s,.txt$,,;rename$f,$_}<*>'

  perl -e'map{rename$`.$&,$`if/\.txt$/}<*>'

I thought maybe a nasty uncaptured Unix `mv` would help, but since the
glyph for that clashes with $`, it doesn't:

  perl -e'map{`mv $\`$& $\``if/\.txt$/}<*>'
  perl -e'map{qx{mv $`$& $`}if/\.txt$/}<*>'

Smylers



------------------------------

Date: Wed, 06 Sep 2000 13:56:16 -0700
From: Matthew Stoker <matt.stoker@motorola.com>
Subject: Re: golf: remove .txt from filenames
Message-Id: <39B6AF70.945005F8@motorola.com>

perl -e'/(.+)\.txt$/&&rename$_,$1for<*>'  - Larry Rosler (syntax error)
perl -e'/\.txt$/&&rename$_,$`for<*>'      - Yanick Champoux (syntax
error)
perl -e'map{?(.*).txt$?;rename$&,$1}<*>'  - Andrew N. McGuire(only
changes 1st file)
ls|perl -ne'/\.txt$/&&rename$_,$`'        - Abigail (does nothing)

^^^^^^ These don't seem to work on my machine. (Maybe I'm doing
something wrong)


perl -e'map{rename$_,substr$_,0,-4}<*.txt>' <-- here's my entry (it
works)


These others work, but are longer:

perl -e'map{$f=$_;s,.txt$,,;rename$f,$_}<*>'         -Andrew N. McGuire
perl -e'for(<*.txt>){rename $_,substr $_,0,-4}'      -Another entry by
me
perl -le'for(<*.txt>){s/\.txt$//;rename"$_.txt",$_}' - Calle Dybedahl
perl -e 'foreach(<*>) { next unless /^(.*)\.txt$/;rename $_,$1}' -
Stephen Kloder
-- 
/------------------------------------------------------------------\
| Matt Stoker                |     email: matt.stoker@motorola.com |
| Unit Process Modeling      | Mail Drop: M360                     |
| DigitalDNA(TM) Laboratories|     Phone: (480)655-3301            |
| Motorola, SPS              |       Fax: (480)655-5013            |
| 2200 W Broadway Road       |     Pager: (888)699-8803            |
| Mesa, AZ 85202             |                                     |
\------------------------------------------------------------------/


------------------------------

Date: Wed, 6 Sep 2000 21:59:28 +0100 (BST)
From: Smylers-usenet@stripey.com (Smylers)
Subject: Re: golf: remove .txt from filenames
Message-Id: <2000Sep6.205929.27512@leeds.ac.uk>

Larry Rosler <lr@hpl.hp.com> uttered something along the lines of:

> Same way, but more compact:
> 
> perl -e'/(.+)\.txt$/&&rename$_,$1for<*>'

Combining your flow with my regexp:

  perl -e'/\.txt/&&rename$`.$&,$`for<*>'

Smylers



------------------------------

Date: Wed, 6 Sep 2000 22:05:38 +0100 (BST)
From: Smylers-usenet@stripey.com (Smylers)
Subject: Re: golf: remove .txt from filenames
Message-Id: <2000Sep6.210539.28223@leeds.ac.uk>

I <Smylers-usenet@stripey.com> uttered something along the lines of:

> Larry Rosler <lr@hpl.hp.com> uttered something along the lines of:
> 
> > perl -e'/(.+)\.txt$/&&rename$_,$1for<*>'
> 
>   perl -e'/\.txt/&&rename$`.$&,$`for<*>'

But then putting your $ back in there so that the thing actually does
what it's supposed to:

    perl -e'/\.txt$/&&rename$`.$&,$`for<*>'

Ooops.

Smylers



------------------------------

Date: Wed, 06 Sep 2000 14:03:51 -0700
From: Matthew Stoker <matt.stoker@motorola.com>
Subject: Re: golf: remove .txt from filenames
Message-Id: <39B6B137.8E8A5E7B@motorola.com>

Matthew Stoker wrote:
> 
> perl -e'/(.+)\.txt$/&&rename$_,$1for<*>'  - Larry Rosler (syntax error)
> perl -e'/\.txt$/&&rename$_,$`for<*>'      - Yanick Champoux (syntax
> error)
> perl -e'map{?(.*).txt$?;rename$&,$1}<*>'  - Andrew N. McGuire(only
> changes 1st file)
> ls|perl -ne'/\.txt$/&&rename$_,$`'        - Abigail (does nothing)

> ^^^^^^ These don't seem to work on my machine. (Maybe I'm doing something wrong)

Uri Guttman's correction to Abigail's entry does the trick:

  ls|perl -lne'/\.txt$/&&rename$_,$`'

is the current champion!

> 
> perl -e'map{rename$_,substr$_,0,-4}<*.txt>' <-- here's my entry (it
> works)
> 
> These others work, but are longer:
> 
> perl -e'map{$f=$_;s,.txt$,,;rename$f,$_}<*>'         -Andrew N. McGuire
> perl -e'for(<*.txt>){rename $_,substr $_,0,-4}'      -Another entry by
> me
> perl -le'for(<*.txt>){s/\.txt$//;rename"$_.txt",$_}' - Calle Dybedahl
> perl -e 'foreach(<*>) { next unless /^(.*)\.txt$/;rename $_,$1}' -
> Stephen Kloder

Thanks, for a load of fun and a little education. Now it's back to work!

-- 
/------------------------------------------------------------------\
| Matt Stoker                |     email: matt.stoker@motorola.com |
| Unit Process Modeling      | Mail Drop: M360                     |
| DigitalDNA(TM) Laboratories|     Phone: (480)655-3301            |
| Motorola, SPS              |       Fax: (480)655-5013            |
| 2200 W Broadway Road       |     Pager: (888)699-8803            |
| Mesa, AZ 85202             |                                     |
\------------------------------------------------------------------/


------------------------------

Date: Wed, 06 Sep 2000 18:06:03 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Good companion book to Programming Perl?
Message-Id: <39b6878a.a33$d3@news.op.net>

In article <2_st5.1671$Xq2.114107@news.uswest.net>,
Christopher M. Jones <christopher_j@uswest.net> wrote:
>Scene: Me and Paul Hoffman (writer of Perl 5 for Dummies) in a room.

I gather that a lot of the problems in the book are the fault of the
publisher and of the editing process, and not actually attributable to
Hoffman.  You can see evidence of this right on the front cover, where
it says

        A Reference for the Rest of Us

They clearly weren't sure whether they wanted a reference or a
tutorial.  Or rather, they *were* sure:  They wanted it to be both.

One of my biggest complaints was

        `Dummy' approach encourages and reinforces the reader's disability 

Clearly, this isn't Paul Hoffman's fault.

My review I probably should have been more explicit about putting some
of the blame on the editorial and publishing process.  At the time I
wrote it, I considered doing this, and then I decided that Hoffman's
name was on the cover and that authors have to take ultimate
responsibility for what appears under their name.  If I were doing it
over, I might choose differently.




------------------------------

Date: Wed, 06 Sep 2000 19:47:24 GMT
From: Andrew Collington <andrew@innismaggiore.com>
Subject: Help needed - regexp
Message-Id: <39B69F28.1EA0874A@innismaggiore.com>

Hi there,

I need help to solve a little problem I'm having...  What I'm trying to
do is replace certain tags in one line with whatever is in the tag plus
some extra text.  So if I have the line like this:

$line = "{icon1.gif}  {icon2.gif}  {header.jpg}";

then after the substitution is needds to look like:

(print $line ouptut)
<img src="../images/icon1.gif" border="0"> <img
src="../images/icon2.gif" border="0"> <img src="../images/header.jpg"
border="0">

but all I'm getting is:

<img src="../images/icon1.gif}  {icon2.gif} {header.jpg" border="0">

I've tried it like:

$foo =~ s/{(.*)}/<img src="$config{'img_icons'}\/$1" border="0">/ig;
$foo =~ tr/{(.*)}/<img src="$config{'img_icons'}\/$1" border="0">/;

but no luck.  I imagine I have to put this in some kind of for loop, but
I'm not sure how in relation to the regexp I have to use.

If anyone could tell me how to do this I would REALLY appreciate it!
Thanks so much!

andy




------------------------------

Date: Wed, 6 Sep 2000 13:14:13 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Help needed - regexp
Message-Id: <MPG.1420456f609eb7e598ad2c@nntp.hpl.hp.com>

In article <39B69F28.1EA0874A@innismaggiore.com> on Wed, 06 Sep 2000 
19:47:24 GMT, Andrew Collington <andrew@innismaggiore.com> says...
> Hi there,

Hi!

> I need help to solve a little problem I'm having...  What I'm trying to
> do is replace certain tags in one line with whatever is in the tag plus
> some extra text.  So if I have the line like this:
> 
> $line = "{icon1.gif}  {icon2.gif}  {header.jpg}";
> 
> then after the substitution is needds to look like:
> 
> (print $line ouptut)
> <img src="../images/icon1.gif" border="0"> <img
> src="../images/icon2.gif" border="0"> <img src="../images/header.jpg"
> border="0">
> 
> but all I'm getting is:
> 
> <img src="../images/icon1.gif}  {icon2.gif} {header.jpg" border="0">
> 
> I've tried it like:
> 
> $foo =~ s/{(.*)}/<img src="$config{'img_icons'}\/$1" border="0">/ig;

You are oh, so close.  All you need is to use a non-greedy match.  See 
perlre.

I used a different delimiter to avoid an extra backslash, and eliminated 
some other unnecessary cruft.

  $foo =~ s!{(.*?)}!<img src="$config{img_icons}/$1" border="0">!g;

> $foo =~ tr/{(.*)}/<img src="$config{'img_icons'}\/$1" border="0">/;

The tr() operator deals with single characters, not strings.  See 
perlop.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Wed, 06 Sep 2000 13:21:02 -0700
From: Matthew Stoker <matt.stoker@motorola.com>
Subject: Re: Help needed - regexp
Message-Id: <39B6A72E.72979D40@motorola.com>

Andrew Collington wrote:
> 
> Hi there,
> 
> I need help to solve a little problem I'm having...  What I'm trying to
> do is replace certain tags in one line with whatever is in the tag plus
> some extra text.  So if I have the line like this:
> 
> $line = "{icon1.gif}  {icon2.gif}  {header.jpg}";
> 
> then after the substitution is needds to look like:
> 
> (print $line ouptut)
> <img src="../images/icon1.gif" border="0"> <img
> src="../images/icon2.gif" border="0"> <img src="../images/header.jpg"
> border="0">
> 
> but all I'm getting is:
> 
> <img src="../images/icon1.gif}  {icon2.gif} {header.jpg" border="0">
> 
> I've tried it like:
> 
> $foo =~ s/{(.*)}/<img src="$config{'img_icons'}\/$1" border="0">/ig;
> $foo =~ tr/{(.*)}/<img src="$config{'img_icons'}\/$1" border="0">/;
> 

You're on the right track, but the intermediate }'s are gettomg gobbled
up by the greedy .* expression. You want the non-greedy form (check the
perl doc's for more information on Quantifiers).

Try using .*? instead of .* like this:

$foo =~ s/{(.*?)}/<img src="$config{'img_icons'}\/$1" border="0">/ig;

The output I get is:

<img src="/icon1.gif" border="0">  <img src="/icon2.gif" border="0"> 
<img src="/header.jpg" border="0">

-- 
/------------------------------------------------------------------\
| Matt Stoker                |     email: matt.stoker@motorola.com |
| Unit Process Modeling      | Mail Drop: M360                     |
| DigitalDNA(TM) Laboratories|     Phone: (480)655-3301            |
| Motorola, SPS              |       Fax: (480)655-5013            |
| 2200 W Broadway Road       |     Pager: (888)699-8803            |
| Mesa, AZ 85202             |                                     |
\------------------------------------------------------------------/


------------------------------

Date: Wed, 6 Sep 2000 15:37:12 -0500
From: "ZLI" <zli@umr.edu>
Subject: Re: Help needed - regexp
Message-Id: <39b6ac07@news.cc.umr.edu>

Maybe you can exclude the "{", "}" signs in the pattern by:
$foo =~ s/{[^{}]+}/<img src="$config{'img_icons'}\/$1" border="0">/ig;

Z. Li.






------------------------------

Date: Wed, 06 Sep 2000 20:41:48 GMT
From: Andrew Collington <andrew@innismaggiore.com>
Subject: Re: Help needed - regexp
Message-Id: <39B6ABE6.7C74230@innismaggiore.com>

hi :)

Larry Rosler wrote:

> You are oh, so close.  All you need is to use a non-greedy match.  See
> perlre.
>
> I used a different delimiter to avoid an extra backslash, and eliminated
> some other unnecessary cruft.
>
>   $foo =~ s!{(.*?)}!<img src="$config{img_icons}/$1" border="0">!g;
>
> > $foo =~ tr/{(.*)}/<img src="$config{'img_icons'}\/$1" border="0">/;
>
> The tr() operator deals with single characters, not strings.  See
> perlop.

That worked wonderfully!!  Thank you so much for your help, Larry :)  I'll be
sure to check out those specific docs first when I next have a regexp
question.  It's hard sometimes to know where to look if you don't really know
what you're looking for ;)

thanks again - I appreciate your help!

Andy




------------------------------

Date: 6 Sep 2000 16:53:32 -0400
From: darkon@one.net (David Wall)
Subject: Re: Help needed - regexp
Message-Id: <8FA7AEBA4darkononenet@206.112.192.118>

andrew@innismaggiore.com (Andrew Collington) wrote in 
<39B69F28.1EA0874A@innismaggiore.com>:

>$foo =~ s/{(.*)}/<img src="$config{'img_icons'}\/$1" border="0">/ig;

The greedy match .* is the problem.  Use .*? instead.  See perldoc perlre.

The following worked for me:

$line =~ s/{(.*?)}/<img src="$config{'img_icons'}\/$1" border="0">/ig;

-- 
David Wall
darkon@one.net


------------------------------

Date: Wed, 6 Sep 2000 14:31:15 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Help needed - regexp
Message-Id: <MPG.1420577c6f7592ae98ad2e@nntp.hpl.hp.com>

In article <39b6ac07@news.cc.umr.edu> on Wed, 6 Sep 2000 15:37:12 -0500, 
ZLI <zli@umr.edu> says...
> Maybe you can exclude the "{", "}" signs in the pattern by:
> $foo =~ s/{[^{}]+}/<img src="$config{'img_icons'}\/$1" border="0">/ig;

Maybe, but not that way, because nothing is captured into $1, is it?

It is courteous to test conjectures before posting them.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Wed, 06 Sep 2000 16:13:12 -0400
From: Thomas George <ygguh@aol.com>
Subject: Help with Expect Perl Script
Message-Id: <u99drs8a6bu6pctah80damaamiocd502hr@4ax.com>

Below is a snippet of my script which doesn't work correctly, or should I say,
it doesn't return the information I require. What the script does is connect up
to a UNIX box and runs a perl script which checks a userid against a reservation
file, similar to struct passwd. 

If the userid is not in the reservation file, it is then entered and I will
receive a return message of: "0, USERID reserved".

If the userid is already in the reservation file, I will then receive a return
message of: "1, USERID exists".

And, if both the above two conditions fail, or if the userid is not within a
predefined format, I will then receive a return message of: "#, Error <REASON>"
where "#" is a number between 2 and 20 and "REASON" is a test error message.

As you will see, I have tried several ways of capturing the return code from my
expect command with no positive results.

Any help would be appreciated.

#!/usr/local/bin/perl

use Expect;     # This is a module, needs supporting modules too.

$Expect::Log_Stdout=1;
$Expect::Debug=3;
$Expect::Exp_Internal=1;

# Basic stuff to setup session.
$cmd = "/usr/bin/telnet" ;
$host = "smtp.server.net." ;
$login = "george" ;
$passwd = "abc123" ;

# Our arguments.
$NAME = $ARGV[0] ;

# Count the command line args, if there's not enough, give usage and exit.
$count = @ARGV ;
if ($count < 1) {
    print "Usage: usercheck.pl NAME\n" ;
    exit 0 ;
    } else { # Connect to the remote host.
         $expect = Expect->spawn("$cmd $host") || die "Can't connect to $host" ;
          $expect->log_stdout(0) ; # Log to STDOUT.
          unless ($expect->expect(5, "login:")) {     # Wait for login prompt.
                print "Error: host timed out waiting for $host\r"
          }
          print $expect "$login\r" ; # Send our username.
          unless ($expect->expect(5, "Password:")) {    # Wait for Password.
                print "Error: login timed out waiting for $host\r"
          }
        print $expect "$passwd\r" ;  # Send our passwd.
        unless ($expect->expect(5, "\$")) {
                print "Error: passwd timed out waiting for $host\r"
        }

        #($code,$message)=$expect->expect(5,"./usercheck $NAME\n") ;
         print $expect "./usercheck $NAME\n" ;
         ($code,$message)=$expect->expect(5,'-re','[0-9]*');
        
        $status = $code;
        
        if ($status == 0) {
                print "Okay\r";
        } else {
                print "Not $message\r";
        }

          print $expect->exp_match();
          # $expect->soft_close() ;
      }
exit 0 ;




------------------------------

Date: Wed, 6 Sep 2000 12:26:04 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Help with looping through code needed
Message-Id: <MPG.14203a23551d955a98ad2a@nntp.hpl.hp.com>

In article <lhut5.1886$Xq2.151410@news.uswest.net> on Wed, 6 Sep 2000 
09:29:03 -0700, Christopher M. Jones <christopher_j@uswest.net> says...
> #/usr/local/bin/perl
> 
> $String = 'This is a <type>COOL Kevin</type> <type>COOL
> Kevin2</type>string!';
> 
> while ( $String =~ s{<type>(.*?)</type>}{}is )
>   { print "String: $1\n"; }
> 
> ###############
> 
> Now the explanation.
> 
> The regex in the while loop will replace any <type>...</type>
> section with nothing (btw, if you need to keep $String for
> some other purpose, you might want to make a copy of it and
> use that).

There is no need to destroy the value of $String.

  while ( $String =~ m{<type>(.*?)</type>}gis )
    { print "String: $1\n"; }

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4239
**************************************


home help back first fref pref prev next nref lref last post