[28626] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9990 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 20 21:05:53 2006

Date: Mon, 20 Nov 2006 18:05:06 -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           Mon, 20 Nov 2006     Volume: 10 Number: 9990

Today's topics:
    Re: Can perl find strings over multiple lines? <DJStunks@gmail.com>
    Re: Do U use >>>>>perl -e 'use re debug;/REGEX/' so U c <tadmc@augustmail.com>
    Re: how to execute 30 transactions at a time <cgrady357@gmail.com>
    Re: how to execute 30 transactions at a time <noreply@gunnar.cc>
    Re: how to execute 30 transactions at a time <someone@example.com>
    Re: How to post back the data by selecting a value from <tadmc@augustmail.com>
    Re: join based on conditions <someone@example.com>
        matching over multiple lines <magnetfreak@gmail.com>
    Re: parsing a string <tadmc@augustmail.com>
    Re: string assignment and concatenation <justin.0611@purestblue.com>
    Re: string assignment and concatenation <justin.0611@purestblue.com>
    Re: string assignment and concatenation <dguttadauro@4ecp.com>
    Re: string assignment and concatenation <DJStunks@gmail.com>
    Re: string assignment and concatenation <dt.news@mailnull.com>
        using an array to set up hash  keys <tidusx2@cogeco.ca>
    Re: using an array to set up hash  keys <someone@example.com>
    Re: using an array to set up hash  keys <tidusx2@cogeco.ca>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 20 Nov 2006 15:07:42 -0800
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Can perl find strings over multiple lines?
Message-Id: <1164064062.449826.110620@k70g2000cwa.googlegroups.com>

Vronans wrote:
> Paul Lalli wrote:
> > osiris@abydos.kmt wrote:
> >> Is it possible to search for strings in a file over multiple lines
> >> using a one-liner from the shell?
> >
> > Yes, it is.
> > <snip>
> > post your best attempt to solve the problem
> > you're having, along with a description of how your attempt is not
> > working sufficiently.  Be sure to include example input, desired
> > output, and actual output.
>
> While it's always good for one to attempt to solve their own problem, I
> don't see why the assumption is often made that they did not do so.
> Further more, why are some people so concerned with that in the first
> place? Especially for a potentially simple answer in this case.
>
> He gave a description of what he was trying to do. You could of included
> an answer similar like mine )below) instead of just general guidelines
> and leave it at that. Do not get me wrong, your guidelines are good for
> general purposes, but by themselves do not really offer anything to the
> topic it self.
>
> It sounds to me like he could find the 's' modifier for a regex match,
> which cause the '.' meta char to match embedded new lines.
>
> This should to do what the OP wants (un tested):
>
> @matches = $full_text =~ m!--(.*?)\)\$!sg;

Aside from the points Paul made in rebuttal with which I agree
strongly, I think it's worth mentioning that your solution is by your
admission untested, and "should" do what the OP wants provided you've
interpreted his description correctly.

Anything I post I test, something made impossible by not having sample
input and desired output.

Secondly, we have, many times in the past, provided solutions to
posters only to find out later on that their description was poor, and
frequently misses edge cases.  I would rather give a definitive answer
once than multiple guesses at potential solutions.

Finally, the posting guidelines are to help the posters, not the
responders.  Programming is, and must always be, an exact science.  If
an individual cannot express their issue exactly and specifically I
don't think they're going to have much luck in their programming
career.  Getting them to formulate such a question should help them
think logically and rationally, but if not, I'm sure "ballet reviewer"
is still available as a career choice.

-jp



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

Date: Mon, 20 Nov 2006 19:44:25 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Do U use >>>>>perl -e 'use re debug;/REGEX/' so U can help??
Message-Id: <slrnem4mfp.blr.tadmc@tadmc30.august.net>

robertospara <robertospara@gmail.com> wrote:
>
> Don't piss me off Deutche Jurgen ...


You have pissed off many of us, so take it like a man.


> On 20 Lis, 14:35, "Jürgen Exner" <jurge...@hotmail.com> wrote:
>> robertospara wrote:
>> > So MONKS OF THE PERL
>> > ???????????????????????????????????????????????????????
>> > Are you still
>> > ALIVE?????????????????????????????????????????????????????????????Would you mind
>>     - not top posting?
>>     - not full quoting?
>>     - repairing your keyboard?
>> 
>> jue
>


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


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

Date: 20 Nov 2006 16:57:02 -0800
From: "Craig" <cgrady357@gmail.com>
Subject: Re: how to execute 30 transactions at a time
Message-Id: <1164070622.375154.39710@m7g2000cwm.googlegroups.com>

>      while ( my @part = splice @arr, 0, 30 ) {  querydb( @part );    }

Wouldn't that load 31, not 30?  :-)



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

Date: Tue, 21 Nov 2006 02:06:26 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to execute 30 transactions at a time
Message-Id: <4sf1ojFv8225U1@mid.individual.net>

Craig wrote:
> Gunnar Hjalmarsson wrote:
>> alwaysonnet wrote:
>>> how can i implement so that every-time only 30 queries will be loaded 
>>> and rest will be loaded after their execution.
>> 
>>     while ( my @part = splice @arr, 0, 30 ) {
>>         querydb( @part );
>>     }
> 
> Wouldn't that load 31, not 30?  :-)

No.

     perldoc -f splice

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Tue, 21 Nov 2006 01:07:30 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: how to execute 30 transactions at a time
Message-Id: <mjs8h.12569$_Z2.10508@edtnps89>

Craig wrote:
>>     while ( my @part = splice @arr, 0, 30 ) {  querydb( @part );    }
> 
> Wouldn't that load 31, not 30?  :-)

$ perl -le'my @arr = 1 .. 99; my @part = splice @arr, 0, 30; print "@part"'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: Mon, 20 Nov 2006 19:55:07 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to post back the data by selecting a value from drop down list
Message-Id: <slrnem4n3r.blr.tadmc@tadmc30.august.net>

Kuna <kunanu@gmail.com> wrote:

> I have a problem in populating data by selecting a value from a drop
> down list I do not have the sample code for this, 


Why not?


> So pease
> help me, its urgent for me.


I was going to help you, but since it was posted several hours ago,
and it was urgent, you are probably already dead, so there doesn't
seem to be much point.


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


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

Date: Mon, 20 Nov 2006 23:13:30 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: join based on conditions
Message-Id: <uEq8h.12499$_Z2.9847@edtnps89>

Sharif Islam wrote:
> I need to join several variables based the value (0 or 1). I only want
> to join if the variables contain one.
> 
> 
> #!/usr/bin/perl
> use strict;
> 
> my ($restriction1, $restriction2,$restriction3,$restriction4)  ;
> #either one or all could be 0 or 1
> 
> # if they are all one, this works
> $restriction1=1;
> $restriction2 =1;
> $restriction3 =1;
> $restriction4=1 ;
> 
> if ($restriction1 == 1 || $restriction2 == 1 || $restriction3 == 1 ||
> $restriction4 ==1) {
>     print join ('|', $restriction1,
> $restriction2,$restriction3,$restriction4);
>     print "\n";
> }
> 
> $restriction1=0; $restriction2 =1; $restriction3 =1; $restriction4=1 ;
> # I don't want to include zero in the join, how??
> 
> if ($restriction1 == 1 || $restriction2 == 1 || $restriction3 == 1 ||
> $restriction4 ==1) {
>     print join ('|', $restriction1,
> $restriction2,$restriction3,$restriction4);
>     print "\n";
> }

print join '|', grep $_, $restriction1, $restriction2, $restriction3,
$restriction4;




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: 20 Nov 2006 17:39:24 -0800
From: "cyborg" <magnetfreak@gmail.com>
Subject: matching over multiple lines
Message-Id: <1164073163.998031.165370@m7g2000cwm.googlegroups.com>

When I was starting to learn regexes in Perl (2 days ago), I picked up
some books and some websites and read a bunch. When I though I was
ready to go, I realized none of those sources taught me how to actually
write a Perl program from start to end that would open the file I
wanted to parse and save the parsing results to a second file. That was
a bummer.

Bla bla bla etc etc etc all those boring stuff everyone hates to read
about other people's life bla bla bla.

Okay, finally I have created a template for my regexes to parse a file,
save results to another file, and have its matches work OVER MULTIPLE
LINES. I know this is far from exciting for you perl hackers, but do
realize that the books I've read don't teach this. (I've got ADHD so if
they do and I'm just a poor reader, nevermind that statement).
Also, please understand that when I say "i have created" I mean "I,
with the help of loads of other people's work and some people's help"
(because let's face it, it's not that big of a file to need help from
loads of people). Of course I don't want credit for this, what I do
want is help. Everything works but some parts I don't understand why.
Also, I know there are probably better ways to go about some stuff,
like I think there's that "or die" stuff that would do what the
"unless" is doing now.

There are also some comments to help beginners (actually they're to
help me, a beginner too, not forget what each of the lines do)
understand what each part is doing and how it contributes to the
program.

So consider this thread as if I were asking you "how do I match over
multiple lines? could you provide full perl code?" and then you replied
me with some code.

Here it is:

#############################################
#*                                         *#
#   TEMPLATE FOR PERL REGEX PROGRAMS        #
#                                           #
#  THIS TEMPLATE DOES THE FOLLOWING:        #
#                                           #
#=3D> reads input file and writes output file #
#=3D> undefines line terminator so that you   #
#   can match over multiple lines autolly   #
#                                           #
#                                           #
# > to choose files from the prompt:        #
# my $source=3D$ARGV[0];                      #
# my $dest=3D$ARGV[1];                        #
#                                           #
#*                                         *#
#############################################


#                      all variables must be declared
#______________________perl warns us about anything wrong
use strict;
use warnings;

#______________________these are the filenames
my $source=3D"r.txt";
my $dest=3D"r2.txt";

#______________________to store the lines we'll be reading
my $line;

#______________________do away with line breaks
$/ =3D undef;
# comment the above line out and the parser won't
# match over multiple lines anymore.

#______________________check file existence and permission
unless($source and $dest){
  print "Source or destination file missing\n";
}

#______________________open input and output files
open SOURCE, "<$source";
open DEST, ">$dest";

#______________________read file till eof
while($line =3D <SOURCE>){

  # replace "if" for "while" and it will print the first
  # match and nothing more. don't know why.
  # take away g and it will print the first match infinite
  # times. don't know why.
  # take away s and it won't match over multiple lines
  # anymore. that's because s makes . match \n
  # the $/=3Dundef above is just for the file reading
  # part, i guess. it doesn't nullify \n

  while($line =3D~ m/<(.*?)>/gs) {
    print DEST "----$1----\n";
  }
}

#______________________close input and output files
close SOURCE;
close DEST;




Just save r.txt with this to test it:

tag"><1b>word<2/div>

<3div class=3D"okay"><4i>o.
<5/i> notgood,
akdjsf jkdmhf djaf =3D=A8?#$
<6flunk>yes but<7
this is
 . a
 . multiline
 . string, the kind of which my
 . template matches
  :) , yes, > maybe we can

but we should <8be> careful




Any improvements will be appreciated.



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

Date: Mon, 20 Nov 2006 19:56:47 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: parsing a string
Message-Id: <slrnem4n6v.blr.tadmc@tadmc30.august.net>

marie <mariecuddy@gmail.com> wrote:
> I have a string for example "perl878juio"
>
> I want to cut off everthing beginning with the first number, so I would
> be left with "perl"
>
> Is there a simply way to do this?


Yes.


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


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

Date: Mon, 20 Nov 2006 22:51:34 +0000
From: Justin C <justin.0611@purestblue.com>
Subject: Re: string assignment and concatenation
Message-Id: <justin.0611-ADECCB.22513420112006@stigmata>

In article <45620da6$0$21183$88260bb3@free.teranews.com>,
 dt <dt.news@mailnull.com> wrote:

> Justin C wrote:
> 
> > #!/usr/bin/perl
> > 
> > use warnings ;
> > use strict ;
> > use File::Copy ;
> > 
> > open ( CSV, '<', "forthcoming_releases.csv" )
> >         or die "Cannot open csv file: $!" ;
> > 
> > foreach ( <CSV> ) {
> >     chomp ;
> >     if ( my ($newname, undef, undef, undef, $oldname) = split /,/ ) {
> >         print $newname, "\t", $oldname, "\n" ;
> >         $newname .= ".jpg" ;
> >         $oldname = $oldname . ".jpg" ;
> >         print $newname, "\t", $oldname, "\n" ;
> >         move ( $oldname, $newname ) ;
> 
> Do you mean to use rename here?
> 
> perldoc -f rename
> 
> From 'perldoc perlfaq5',
> 
> How can I reliably rename a file?
> 
> If your operating system supports a proper mv(1) utility or its functional
> equivalent, this works:
> 
>     rename($old, $new) or system("mv", $old, $new);
> 
> It may be more portable to use the File::Copy module instead. You just copy
> to the new file to the new name (checking return values), then delete the
> old one. This isn't really the same semantically as a rename(), which
> preserves meta-information like permissions, timestamps, inode info, etc.

What part of my post didn't you understand that lead you to post this? 
> 
> Newer versions of File::Copy export a move() function.

Ooh! Smart cookie, did you even read what I posted?

-- 
Justin C, by the sea.


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

Date: Mon, 20 Nov 2006 23:01:30 +0000
From: Justin C <justin.0611@purestblue.com>
Subject: Re: string assignment and concatenation
Message-Id: <justin.0611-38F80C.23013020112006@stigmata>

In article <1164056282.120134.76240@h54g2000cwb.googlegroups.com>,
 "Dean G." <dguttadauro@4ecp.com> wrote:

> Justin C wrote:
> > #!/usr/bin/perl
> >
> > use warnings ;
> > use strict ;
> > use File::Copy ;
> >
> > open ( CSV, '<', "forthcoming_releases.csv" )
> >         or die "Cannot open csv file: $!" ;
> >
> > foreach ( <CSV> ) {
> >     chomp ;
> >     if ( my ($newname, undef, undef, undef, $oldname) = split /,/ ) {
> >         print $newname, "\t", $oldname, "\n" ;
> >         $newname .= ".jpg" ;
> >         $oldname = $oldname . ".jpg" ;
> >         print $newname, "\t", $oldname, "\n" ;
> >         move ( $oldname, $newname ) ;
> >     }
> > }
> >
> >
> > The two print statements are there to help me debug, but they're no help!
> >
> > A sample of the CSV:
> >
> > 1,AC/DC,2003 Logo,TS,ts_ac_2003
> > 2,AC/DC,A5 Highway Fire,JO,jo_ac_a5highw
> > 3,AC/DC,Album Stiff,TS,ts_ac_albumst
> > 4,AC/DC,Amp,TS,ts_ac_amp
> > 5,AC/DC,Angus,TS,ts_ac_angusb
> > 6,AC/DC,Angus Caricature,SB,sb_ac_angus
> > 7,AC/DC,Angus Comin' At Ya,HF,hf_ac_angusco
> > 8,AC/DC,Angus For Those,TS,ts_ac_angusf
> > 9,AC/DC,Angus Head,RP,rp_ac_angushe
> > 10,AC/DC,Angus Let,TS,ts_ac_angusle
> >
> >
> > The last field in the CSV is the current filename without the .jpg,
> > the first field is a unique number, I'm trying to name these files
> > sequentially, but with .jpg
> >
> > As you can see I've tried two methods for concatenation and neither
> > seems to do what I'd expect. $oldname never gets .jpg appended and
> > $newname starts of being .jpg, then .jpgpj, and lastly (for 3 digit
> > numbers) .jpgjpg. I can see what is happening with $newname but don't
> > understand why.
> >
> > If someone could point me at an explanation here I'd be grateful. I've
> > never had trouble with assignment before, well, not like this. The code
> > looks right to me but obviously I know nothing!
> >
> > Thanks for any help you can give.
> 
> I'm not sure what to say, since it seems to work for me. I have
> commented out the move line, as I obviously don't have the same files,
> but the prints seem to print what you are looking for.
> 
> I'm using v5.8.7.

5.8.4, but I can't believe that there is a bug here. I can understand 
them in the far reaches of rarely used bits of perl, but assignment?
> 
> What does your output look like ?

A sample is below but the upshot is: .jpg doesn't get appended to 
$oldname and $newname contains just .jpg as here:

1       ts_ac_2003
 .jpgg   ts_ac_2003
2       jo_ac_a5highw
 .jpgg   jo_ac_a5highw
3       ts_ac_albumst
 .jpgg   ts_ac_albumst
4       ts_ac_amp
 .jpgg   ts_ac_amp
5       ts_ac_angusb
 .jpgg   ts_ac_angusb
6       sb_ac_angus
 .jpgg   sb_ac_angus
7       hf_ac_angusco
 .jpgg   hf_ac_angusco
8       ts_ac_angusf
 .jpgg   ts_ac_angusf
9       rp_ac_angushe
 .jpgg   rp_ac_angushe
10      ts_ac_angusle
 .jpgpg  ts_ac_angusle


> 
> Also, since you don't seem to be moving anything across filesystem
> boundaries, you could also use the rename function instead of
> File::Copy

Thanks for the pointer. I still need to get the assignment right first 
though. I've stared at it until I can't even see the code anymore but 
can't see anything wrong with it. 

As an aside, the perl install on the computer in question serves cgi for 
our in-house web-site without trouble so I'm inclined to think the 
install is OK.... Hmmmm.... 'tis amd64 version of Debian stable though - 
which is unsupported - could have some bugs I suppose.

-- 
Justin C, by the sea.


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

Date: 20 Nov 2006 15:47:49 -0800
From: "Dean G." <dguttadauro@4ecp.com>
Subject: Re: string assignment and concatenation
Message-Id: <1164066469.639734.98040@m73g2000cwd.googlegroups.com>


Justin C wrote:
>
> A sample is below but the upshot is: .jpg doesn't get appended to
> $oldname and $newname contains just .jpg as here:
>
> 1       ts_ac_2003
> .jpgg   ts_ac_2003
> 2       jo_ac_a5highw
> .jpgg   jo_ac_a5highw
> 3       ts_ac_albumst
> .jpgg   ts_ac_albumst
> 4       ts_ac_amp
> .jpgg   ts_ac_amp
> 5       ts_ac_angusb
> .jpgg   ts_ac_angusb
> 6       sb_ac_angus
> .jpgg   sb_ac_angus
> 7       hf_ac_angusco
> .jpgg   hf_ac_angusco
> 8       ts_ac_angusf
> .jpgg   ts_ac_angusf
> 9       rp_ac_angushe
> .jpgg   rp_ac_angushe
> 10      ts_ac_angusle
> .jpgpg  ts_ac_angusle
>
>
> >
> > Also, since you don't seem to be moving anything across filesystem
> > boundaries, you could also use the rename function instead of
> > File::Copy
>
> Thanks for the pointer. I still need to get the assignment right first
> though. I've stared at it until I can't even see the code anymore but
> can't see anything wrong with it.
>
> As an aside, the perl install on the computer in question serves cgi for
> our in-house web-site without trouble so I'm inclined to think the
> install is OK.... Hmmmm.... 'tis amd64 version of Debian stable though -
> which is unsupported - could have some bugs I suppose.
>

In that case, maybe Xho (see message below about embedded control
characters) may be on to something. Try adding

s/[\cA-\cZ]//g;

after the chomp and before the if to strip out the control chars.


Dean G.



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

Date: 20 Nov 2006 15:50:26 -0800
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: string assignment and concatenation
Message-Id: <1164066626.523494.226450@f16g2000cwb.googlegroups.com>

Justin C wrote:
> #!/usr/bin/perl
>
> use warnings ;
> use strict ;
> use File::Copy ;
>
> open ( CSV, '<', "forthcoming_releases.csv" )
>         or die "Cannot open csv file: $!" ;
>
> foreach ( <CSV> ) {
>     chomp ;
>     if ( my ($newname, undef, undef, undef, $oldname) = split /,/ ) {
>         print $newname, "\t", $oldname, "\n" ;
>         $newname .= ".jpg" ;
>         $oldname = $oldname . ".jpg" ;
>         print $newname, "\t", $oldname, "\n" ;
>         move ( $oldname, $newname ) ;
>     }
> }
>
>
> 1,AC/DC,2003 Logo,TS,ts_ac_2003
> 2,AC/DC,A5 Highway Fire,JO,jo_ac_a5highw
> 3,AC/DC,Album Stiff,TS,ts_ac_albumst
> 4,AC/DC,Amp,TS,ts_ac_amp
> 5,AC/DC,Angus,TS,ts_ac_angusb
> 6,AC/DC,Angus Caricature,SB,sb_ac_angus
> 7,AC/DC,Angus Comin' At Ya,HF,hf_ac_angusco
> 8,AC/DC,Angus For Those,TS,ts_ac_angusf
> 9,AC/DC,Angus Head,RP,rp_ac_angushe
> 10,AC/DC,Angus Let,TS,ts_ac_angusle

your assignment seems fine.

I would use a module to simplify things:

  #!/usr/bin/perl

  use warnings;
  use strict;

  use Text::CSV::Simple;

  my $parser = Text::CSV::Simple->new;
  $parser->field_map(qw/id null null null old/);

  for my $line ( $parser->read_file(\*DATA) ) {
  	printf "rename %s.jpg to %d.jpg\n", @{ $line }{'old','id'};
  }

  __DATA__
  1,AC/DC,2003 Logo,TS,ts_ac_2003
  2,AC/DC,A5 Highway Fire,JO,jo_ac_a5highw
  3,AC/DC,Album Stiff,TS,ts_ac_albumst
  4,AC/DC,Amp,TS,ts_ac_amp
  5,AC/DC,Angus,TS,ts_ac_angusb
  6,AC/DC,Angus Caricature,SB,sb_ac_angus
  7,AC/DC,Angus Comin' At Ya,HF,hf_ac_angusco
  8,AC/DC,Angus For Those,TS,ts_ac_angusf
  9,AC/DC,Angus Head,RP,rp_ac_angushe
  10,AC/DC,Angus Let,TS,ts_ac_angusle
  
-jp



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

Date: Mon, 20 Nov 2006 17:00:25 -0800
From: dt <dt.news@mailnull.com>
Subject: Re: string assignment and concatenation
Message-Id: <45624321$0$21095$88260bb3@free.teranews.com>

Justin C wrote:

> In article <45620da6$0$21183$88260bb3@free.teranews.com>,
>  dt <dt.news@mailnull.com> wrote:
> 
>> Justin C wrote:
>> 
>> > #!/usr/bin/perl
>> > 
>> > use warnings ;
>> > use strict ;
>> > use File::Copy ;
>> > 
>> > open ( CSV, '<', "forthcoming_releases.csv" )
>> >         or die "Cannot open csv file: $!" ;
>> > 
>> > foreach ( <CSV> ) {
>> >     chomp ;
>> >     if ( my ($newname, undef, undef, undef, $oldname) = split /,/ ) {
>> >         print $newname, "\t", $oldname, "\n" ;
>> >         $newname .= ".jpg" ;
>> >         $oldname = $oldname . ".jpg" ;
>> >         print $newname, "\t", $oldname, "\n" ;
>> >         move ( $oldname, $newname ) ;
>> 
>> Do you mean to use rename here?
>> 
>> perldoc -f rename
>> 
>> From 'perldoc perlfaq5',
>> 
>> How can I reliably rename a file?
>> 
>> If your operating system supports a proper mv(1) utility or its
>> functional equivalent, this works:
>> 
>>     rename($old, $new) or system("mv", $old, $new);
>> 
>> It may be more portable to use the File::Copy module instead. You just
>> copy to the new file to the new name (checking return values), then
>> delete the old one. This isn't really the same semantically as a
>> rename(), which preserves meta-information like permissions, timestamps,
>> inode info, etc.
> 
> What part of my post didn't you understand that lead you to post this?

The part I didn't understand were the parts you were complaining about.

Those parts work fine for me.

I took a WAG you needed some help elsewhere.

>> Newer versions of File::Copy export a move() function.
> 
> Ooh! Smart cookie, did you even read what I posted?

Yes, I downloaded it and ran it, too.  Works fine for me.

Quit sounding like an ungrateful sloth and accept the help in
the spirit it was given.

-dt

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Mon, 20 Nov 2006 19:44:20 -0500
From: Adam Lawson <tidusx2@cogeco.ca>
Subject: using an array to set up hash  keys
Message-Id: <J%r8h.12301$tP.8865@read2.cgocable.net>

I would like to do the following:

@array qw(one two three four)


and make hash keys from @array and set each value to 1 so my hash would be

%hash (one => '1', two => '1' etc...

How can i do this?

Adam


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

Date: Tue, 21 Nov 2006 01:05:23 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: using an array to set up hash  keys
Message-Id: <nhs8h.12568$_Z2.1436@edtnps89>

Adam Lawson wrote:
> I would like to do the following:
> 
> @array qw(one two three four)
> 
> 
> and make hash keys from @array and set each value to 1 so my hash would be
> 
> %hash (one => '1', two => '1' etc...
> 
> How can i do this?

my %hash;
@hash{ @array } = ( 1 ) x @array;


my %hash = map { $_ => 1 } @array;


my %hash;
$hash{ $_ } = 1 for @array;



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: Mon, 20 Nov 2006 20:56:31 -0500
From: Adam Lawson <tidusx2@cogeco.ca>
Subject: Re: using an array to set up hash  keys
Message-Id: <o3t8h.2871$J32.2050@read1.cgocable.net>

John W. Krahn wrote:
> Adam Lawson wrote:
> 
>>I would like to do the following:
>>
>>@array qw(one two three four)
>>
>>
>>and make hash keys from @array and set each value to 1 so my hash would be
>>
>>%hash (one => '1', two => '1' etc...
>>
>>How can i do this?
> 
> 
> my %hash;
> @hash{ @array } = ( 1 ) x @array;
> 
> 
> my %hash = map { $_ => 1 } @array;
> 
> 
> my %hash;
> $hash{ $_ } = 1 for @array;
> 
> 
> 
> John
Thanks a lot!


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

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


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