[23831] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6034 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 29 21:36:45 2004

Date: Thu, 29 Jan 2004 18:31:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 29 Jan 2004     Volume: 10 Number: 6034

Today's topics:
        perl one-liner to rename files <prakash@ece.arizona.edu>
    Re: perl one-liner to rename files <prakash@ece.arizona.edu>
    Re: perl one-liner to rename files <tadmc@augustmail.com>
    Re: perl one-liner to rename files <tadmc@augustmail.com>
    Re: perl one-liner to rename files <usenet@morrow.me.uk>
    Re: perl one-liner to rename files <lv@aol.com>
    Re: perl one-liner to rename files <cenxnfu@rpr.nevmban.rqh>
    Re: perl one-liner to rename files <gnari@simnet.is>
    Re: perl one-liner to rename files <tadmc@augustmail.com>
    Re: perl one-liner to rename files <lv@aol.com>
    Re: perl one-liner to rename files <gnari@simnet.is>
    Re: perl one-liner to rename files <bik.mido@tiscalinet.it>
    Re: Perl pattern 5.6+ bug causing Parse::Yapp to fail <clint@0lsen.net>
    Re: Perl pattern 5.6+ bug causing Parse::Yapp to fail <clint@0lsen.net>
    Re: Perl pattern 5.6+ bug causing Parse::Yapp to fail <pkent77tea@yahoo.com.tea>
    Re: Perl Pattern Matching-- Newbie (sidsharma)
    Re: Perl Pattern Matching-- Newbie <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 24 Jan 2004 11:34:24 -0700
From: Jayaprakash Rudraraju <prakash@ece.arizona.edu>
To: Jayaprakash Rudraraju <prakash@ece.arizona.edu>
Subject: perl one-liner to rename files
Message-Id: <Pine.GSO.4.50.0401241020560.12731-100000@shelltoe.ece.arizona.edu>


Hi,

I am using the following one-liner to rename files. Can you suggest
different versions of it to acheive same results so that it will be a good
learing experience.

I am not able to avoid print and chomp usage in the one-liner.. but
regular-expression in the substitute was the best I could get.

Thanks,
Prakash.

cat chromats.txt | perl -ne 'chomp; print "mv $_ ";
	s/(p[^\.]*)/s# #sprintf("%-9s", $1)#x/e; print "$_\n"' | sh

contents of chromats.txt

NAT2xxxx00101p71.g.1_047.ab1
NAT2xxxx00101p72.g.1_041.ab1
NAT2xxxx00101p73.g.1_048.ab1
NAT2xxxx00101p77.g.1_042.ab1
NAT2xxxx00101pblank.g.1_034.ab1
NAT2xxxx00101pblank.g.1_082.ab1
NAT2xxxx00101pNA07341.g.1_016.ab1
NAT2xxxx00101pNA12092.g.1_015.ab1
NAT2xxxx00101pNA12093.g.1_031.ab1
NAT2xxxx00101pNA12094.g.1_032.ab1

-- 
Prakash

Off the keyboard, over the bridge, past the hub, thru the
router, down the line, ....nothing but net!!
-------------------------------------
Printed using 100% recycled electrons


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

Date: Sat, 24 Jan 2004 12:34:06 -0700
From: Jayaprakash Rudraraju <prakash@ece.arizona.edu>
Subject: Re: perl one-liner to rename files
Message-Id: <Pine.GSO.4.50.0401241233150.13033-100000@shelltoe.ece.arizona.edu>


This was the one-liner that works:

cat chromats.txt | perl -ne 'chomp; print "mv $_";
	s/(p[^\.]*)/sprintf("%-9s", $1)/e; s/ /x/g; print "$_\n"' | sh

11:34am, IP packets from Jayaprakash Rudraraju delivered:

>
> Hi,
>
> I am using the following one-liner to rename files. Can you suggest
> different versions of it to acheive same results so that it will be a good
> learing experience.
>
> I am not able to avoid print and chomp usage in the one-liner.. but
> regular-expression in the substitute was the best I could get.
>
> Thanks,
> Prakash.
>
> cat chromats.txt | perl -ne 'chomp; print "mv $_ ";
> 	s/(p[^\.]*)/s# #sprintf("%-9s", $1)#x/e; print "$_\n"' | sh
>
> contents of chromats.txt
>
> NAT2xxxx00101p71.g.1_047.ab1
> NAT2xxxx00101p72.g.1_041.ab1
> NAT2xxxx00101p73.g.1_048.ab1
> NAT2xxxx00101p77.g.1_042.ab1
> NAT2xxxx00101pblank.g.1_034.ab1
> NAT2xxxx00101pblank.g.1_082.ab1
> NAT2xxxx00101pNA07341.g.1_016.ab1
> NAT2xxxx00101pNA12092.g.1_015.ab1
> NAT2xxxx00101pNA12093.g.1_031.ab1
> NAT2xxxx00101pNA12094.g.1_032.ab1
>
>

-- 
Prakash

Sometimes I think the surest sign that intelligent life
exists elsewhere in the universe is that none of it has
tried to contact us.  -- Bill Watterson "Calvin and Hobbes"
-------------------------------------
Printed using 100% recycled electrons


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

Date: Sat, 24 Jan 2004 14:20:41 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl one-liner to rename files
Message-Id: <slrnc15ksp.56o.tadmc@magna.augustmail.com>

Jayaprakash Rudraraju <prakash@ece.arizona.edu> wrote:

> I am using the following one-liner to rename files. Can you suggest
> different versions of it to acheive same results so that it will be a good
> learing experience.

> cat chromats.txt | perl -ne 'chomp; print "mv $_ ";
> 	s/(p[^\.]*)/s# #sprintf("%-9s", $1)#x/e; print "$_\n"' | sh


You have a useless use of cat.

Why shell-out to mv(1) when you can (probably) do it 
in native Perl with rename()?

To see what renaming it would do:

   perl -lne '($to = $_) =~ s/(p[^\.]*)/sprintf("%-9s", $1)/e; 
              $to =~ tr/ /x/; 
              print "mv $_ $to"' chromats.txt


To actually do the renaming (untested):

   perl -lne '($to = $_) =~ s/(p[^\.]*)/sprintf("%-9s", $1)/e; 
              $to =~ tr/ /x/; 
              rename $_, $to' chromats.txt


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 24 Jan 2004 14:12:51 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl one-liner to rename files
Message-Id: <slrnc15ke3.56o.tadmc@magna.augustmail.com>

Jayaprakash Rudraraju <prakash@ece.arizona.edu> wrote:
> 
> This was the one-liner that works:
                              ^^^^^

I doubt that that is true.


> cat chromats.txt | perl -ne 'chomp; print "mv $_";
                                                ^^^
                                                ^^^

Where's the space character?


> 	s/(p[^\.]*)/sprintf("%-9s", $1)/e; s/ /x/g; print "$_\n"' | sh


mv with only one argument does NOT work.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 24 Jan 2004 21:03:11 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: perl one-liner to rename files
Message-Id: <buumif$qbi$1@wisteria.csv.warwick.ac.uk>


tadmc@augustmail.com wrote:
> Jayaprakash Rudraraju <prakash@ece.arizona.edu> wrote:
> 
> > I am using the following one-liner to rename files. Can you suggest
> > different versions of it to acheive same results so that it will be a good
> > learing experience.
> 
> > cat chromats.txt | perl -ne 'chomp; print "mv $_ ";
> > 	s/(p[^\.]*)/s# #sprintf("%-9s", $1)#x/e; print "$_\n"' | sh
> 
> 
> You have a useless use of cat.
> 
> Why shell-out to mv(1) when you can (probably) do it 
> in native Perl with rename()?

And if you can't (if you are crossing filesystems), use File::Copy.

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk


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

Date: Sat, 24 Jan 2004 15:17:47 -0600
From: l v <lv@aol.com>
Subject: Re: perl one-liner to rename files
Message-Id: <ShBQb.5897$5M.142550@dfw-read.news.verio.net>

Jayaprakash Rudraraju wrote:
> Hi,
> 
> I am using the following one-liner to rename files. Can you suggest
> different versions of it to acheive same results so that it will be a good
> learing experience.
> 
> I am not able to avoid print and chomp usage in the one-liner.. but
> regular-expression in the substitute was the best I could get.
> 
> Thanks,
> Prakash.
> 
> cat chromats.txt | perl -ne 'chomp; print "mv $_ ";
> 	s/(p[^\.]*)/s# #sprintf("%-9s", $1)#x/e; print "$_\n"' | sh
> 
> contents of chromats.txt
> 
> NAT2xxxx00101p71.g.1_047.ab1
> NAT2xxxx00101p72.g.1_041.ab1
> NAT2xxxx00101p73.g.1_048.ab1
> NAT2xxxx00101p77.g.1_042.ab1
> NAT2xxxx00101pblank.g.1_034.ab1
> NAT2xxxx00101pblank.g.1_082.ab1
> NAT2xxxx00101pNA07341.g.1_016.ab1
> NAT2xxxx00101pNA12092.g.1_015.ab1
> NAT2xxxx00101pNA12093.g.1_031.ab1
> NAT2xxxx00101pNA12094.g.1_032.ab1
> 

adding -l to the command switchs will auto chomp stdin and put newline 
back on stdout.  Note that this will only work in conjunction with -n or 
-p command switches.

Len



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

Date: Sat, 24 Jan 2004 14:44:58 -0700
From: Cognition Peon <cenxnfu@rpr.nevmban.rqh>
Subject: Re: perl one-liner to rename files
Message-Id: <Pine.GSO.4.50.0401241442230.13782-100000@shelltoe.ece.arizona.edu>


Thanks for the suggestions.. It was good know about -l switch. I will
start using it more often :-)

2:20pm, IP packets from Tad McClellan delivered:

> Jayaprakash Rudraraju <prakash@ece.arizona.edu> wrote:
>
> > I am using the following one-liner to rename files. Can you suggest
> > different versions of it to acheive same results so that it will be a good
> > learing experience.
>
> > cat chromats.txt | perl -ne 'chomp; print "mv $_ ";
> > 	s/(p[^\.]*)/s# #sprintf("%-9s", $1)#x/e; print "$_\n"' | sh
>
>
> You have a useless use of cat.
>
> Why shell-out to mv(1) when you can (probably) do it
> in native Perl with rename()?
>
> To see what renaming it would do:
>
>    perl -lne '($to = $_) =~ s/(p[^\.]*)/sprintf("%-9s", $1)/e;
>               $to =~ tr/ /x/;
>               print "mv $_ $to"' chromats.txt
>
>
> To actually do the renaming (untested):
>
>    perl -lne '($to = $_) =~ s/(p[^\.]*)/sprintf("%-9s", $1)/e;
>               $to =~ tr/ /x/;
>               rename $_, $to' chromats.txt
>
>
>

-- 
echo cenxnfu@rpr.nevmban.rqh | perl -pe 'y/A-Za-z/N-ZA-Mn-za-m/'

Q: How many CPU's does it take to execute a job?
A: Four. Three to hold it down, and one to rip its head off.
-------------------------------------
Printed using 100% recycled electrons


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

Date: Sat, 24 Jan 2004 22:17:27 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: perl one-liner to rename files
Message-Id: <buur39$p7o$1@news.simnet.is>

"l v" <lv@aol.com> wrote in message
news:ShBQb.5897$5M.142550@dfw-read.news.verio.net...
> adding -l to the command switchs will auto chomp stdin and put newline
> back on stdout.  Note that this will only work in conjunction with -n or
> -p command switches.

why do uou say that ? (the bit about -n and -p)

perl -le "print 1;print 2;print 3"

gnari





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

Date: Sat, 24 Jan 2004 18:24:58 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl one-liner to rename files
Message-Id: <slrnc1636q.5ch.tadmc@magna.augustmail.com>

Ben Morrow <usenet@morrow.me.uk> wrote:
> tadmc@augustmail.com wrote:


>> Why shell-out to mv(1) when you can (probably) do it 
>> in native Perl with rename()?
> 
> And if you can't (if you are crossing filesystems), use File::Copy.


I didn't realize until after posting that the "probably" qualifier
wasn't needed, as there were no directory separators in the strings.

ie. they are being mv'd in the same directory, so rename() must
work fine.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 24 Jan 2004 22:39:05 -0600
From: l v <lv@aol.com>
Subject: Re: perl one-liner to rename files
Message-Id: <ALHQb.5900$5M.142822@dfw-read.news.verio.net>

gnari wrote:
> "l v" <lv@aol.com> wrote in message
> news:ShBQb.5897$5M.142550@dfw-read.news.verio.net...
> 
>>adding -l to the command switchs will auto chomp stdin and put newline
>>back on stdout.  Note that this will only work in conjunction with -n or
>>-p command switches.
> 
> 
> why do uou say that ? (the bit about -n and -p)
> 
> perl -le "print 1;print 2;print 3"
> 
> gnari
> 
> 
> 

quoting from perldoc perlrun:
-l[octnum]

enables automatic line-ending processing. It has two separate effects. 
First, it automatically chomps $/ (the input record separator) when used 
with -n or -p. Second, it assigns $\ (the output record separator) to 
have the value of octnum so that any print statements will have that 
separator added back on. If octnum is omitted, sets $\ to the current 
value of $/. For instance, to trim lines to 80 columns:
     perl -lpe 'substr($_, 80) = ""'
Note that the assignment $\ = $/ is done when the switch is processed, 
so the input record separator can be different than the output record 
separator if the -l switch is followed by a -0 switch:

     gnufind / -print0 | perl -ln0e 'print "found $_" if -p'
This sets $\ to newline and then sets $/ to the null character.



However, to be more acurate than my previous posting: Note that when 
using -l the chomp will only work in conjunction with -n or -p command 
switches.

Len



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

Date: Sun, 25 Jan 2004 04:48:32 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: perl one-liner to rename files
Message-Id: <buvi0j$2in$1@news.simnet.is>

"l v" <lv@aol.com> wrote in message
news:ALHQb.5900$5M.142822@dfw-read.news.verio.net...
> gnari wrote:
> > "l v" <lv@aol.com> wrote in message
> > news:ShBQb.5897$5M.142550@dfw-read.news.verio.net...
> >
> >>adding -l to the command switchs will auto chomp stdin and put newline
> >>back on stdout.  Note that this will only work in conjunction with -n or
> >>-p command switches.

somehow I parsed this to refer to the back to STDOUT bit

[snip perldoc showing the -l chomp indeed only working with -n and -p]

gnari







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

Date: Mon, 26 Jan 2004 20:45:18 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: perl one-liner to rename files
Message-Id: <qfu910pkq69f4p9juv54rrabkc77t4l3tg@4ax.com>

On Sat, 24 Jan 2004 22:17:27 -0000, "gnari" <gnari@simnet.is> wrote:

>> adding -l to the command switchs will auto chomp stdin and put newline
                                         ^^^^^^^^^^
>> back on stdout.  Note that this will only work in conjunction with -n or
>> -p command switches.
>
>why do uou say that ? (the bit about -n and -p)
>
>perl -le "print 1;print 2;print 3"

It's obvious he refers to auto chomp()ing. I'd say that "half of it"
works only if... ;-) So you're both half right!

Similar misunderstandings tend to arise quite frequently! I had one in
a private e-mail exchange even though we both knew full well both the
behaviour of -n, -p and -ln, -lp resepectively.


Michele


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

Date: Mon, 19 Jan 2004 22:48:06 GMT
From: Clint Olsen <clint@0lsen.net>
Subject: Re: Perl pattern 5.6+ bug causing Parse::Yapp to fail
Message-Id: <slrnc0onl2.6nq.clint@poly.0lsen.net>

On 2004-01-19, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>
> This expression
>
>      /^\s*sub\s+_Parse\s*{\s*$/ ..  /^\s*}\s*#\s*_Parse\s*$/
>
> doesn't look for "sub _Parse {" in the next function, and it would never
> find it unless the source defined _Parse twice.  It looks for the
> final "}#_Parse" that by convention ends that routine.

My understanding of this operator is that it is true once the left hand
side is true and remains true until it finds the left hand pattern.  So, in
essence it grabs the entire contents between these two markers.  Yes, I did
leave off the trailing marker for brevity reasons.  Otherwise the sub was
too long for posting.

The problem is, the first pattern is never matched.  But, when I create a
separate program and run it on this file, it _does_ match.  So, I think
there's likely a bug lurking around somewhere in Perl.

> Is your code below an example of where it fails, or is it the self-
> created program that works as expected?  In any case, it is incomplete
> because the crucial end of the _Parse routine isn't there.  I've left it
> in for reference, but as an aid to answering your question it doesn't
> seem to help much.

As it stands, DBLoad is a sub which is contained within the package that
will be parsed by that pattern shown above.  It grabs the sub in between
the two markers and strips out the #DBG> comments and then 'evals' the code
on the fly to create a new routine.

-Clint


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

Date: Fri, 23 Jan 2004 00:18:37 GMT
From: Clint Olsen <clint@0lsen.net>
Subject: Re: Perl pattern 5.6+ bug causing Parse::Yapp to fail
Message-Id: <slrnc10q2t.6nq.clint@poly.0lsen.net>

On 2004-01-20, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>
> So how can we reproduce the bug, if there is one?  Give us a recipe how
> to use Parse::Yapp so that the error occurs.

That's a good question.

I just tried the example Calc.yp that came with it, and debug mode appears
to be working.  So, it's specific to my module which has sensitive data in
it (can't be distributed).  However, it compiles cleanly under 'strict' and
'warning', so I'm not sure how I could isolate the problem.  As usual with
Perl, I guess I'll have to do the traditional 'binary search' approach
where I gut halves of my code until I can see what's causing it.

Having said that, can you envision why a simple parse like that would fail?

Thanks,

-Clint


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

Date: Sat, 24 Jan 2004 13:55:53 +0000
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: Perl pattern 5.6+ bug causing Parse::Yapp to fail
Message-Id: <pkent77tea-A03BFD.13555324012004@pth-usenet-01.plus.net>

In article <slrnc10q2t.6nq.clint@poly.0lsen.net>,
 Clint Olsen <clint@0lsen.net> wrote:

> On 2004-01-20, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > So how can we reproduce the bug, if there is one?  Give us a recipe how
> > to use Parse::Yapp so that the error occurs.
> 
> That's a good question.
> 
> I just tried the example Calc.yp that came with it, and debug mode appears
> to be working.  So, it's specific to my module which has sensitive data in
> it (can't be distributed).  However, it compiles cleanly under 'strict' and
> 'warning', so I'm not sure how I could isolate the problem.  As usual with
> Perl, I guess I'll have to do the traditional 'binary search' approach
> where I gut halves of my code until I can see what's causing it.

Try peppering your code/tokenizer/whatever with some debugging print() 
statements, and printing out the location and any relevant variable 
values. That might help, as does the debugging mode. Also are you using 
the latest versions of perl, Parse::Yapp, etc?

Try putting all this so-sensitive data at the top of the module rather 
than scattered throughout the code, if it is. That way you can easily 
change the values to something inoffensive if you do need to show other 
people the code if you still need help.

P

-- 
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply


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

Date: 19 Jan 2004 13:43:30 -0800
From: sidsharma@yahoo.com (sidsharma)
Subject: Re: Perl Pattern Matching-- Newbie
Message-Id: <9c3d003b.0401191343.258e409@posting.google.com>

chopra_vandana@yahoo.com (Vandana) wrote in message news:<cfb4ab5c.0401181714.76589773@posting.google.com>...
 
> Example:
> My Error message looks something like this:
> 
>  39212:Tue Dec 30 10:11:55 2003:  (1030) - Windows cannot
> query for the list of Group Policy objects. A message that describes the
> reason for this was previously logged by the policy engine.";
> 
> and I want to check whether this message has
> "query for the list of Group Policy objects"
> 
> Please can you suggest what is the best way to do something like this in
> Perl.

$s = "39212:Tue Dec 30 10:11:55 2003:  (1030) - Windows cannot
query for the list of Group Policy objects. A message that describes the
reason for this was previously logged by the policy engine.";
$t = "query for the list of Group Policy objects";
if ($s=~m/$t/) { # Whatever you want to do with it.;}

Use the match operator m// I suppose....


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

Date: Mon, 19 Jan 2004 17:21:51 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl Pattern Matching-- Newbie
Message-Id: <slrnc0opkf.1k4.tadmc@magna.augustmail.com>

Vandana <chopra_vandana@yahoo.com> wrote:

> My Error message looks something like this:
> 
>  39212:Tue Dec 30 10:11:55 2003:  (1030) - Windows cannot
> query for the list of Group Policy objects. A message that describes the
> reason for this was previously logged by the policy engine.";
> 
> and I want to check whether this message has
> "query for the list of Group Policy objects"
> 
> Please can you suggest what is the best way to do something like this in
> Perl.


   if ( index($msg, 'query for the list of Group Policy objects' >= 0 ) {
      print "matched\n";
   }
   else {
      print "No match\n";
   }


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 6034
***************************************


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