[28625] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9989 Volume: 10

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

Date: Mon, 20 Nov 2006 15: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: 9989

Today's topics:
        Basic Pod::Html useage taantle@gmail.com
    Re: Can perl find strings over multiple lines? <vronans@nowheresville.spamwall>
    Re: Can perl find strings over multiple lines? <mritty@gmail.com>
    Re: Do I *have* to use 'OOP' to use modules? <tzz@lifelogs.com>
    Re: How to change Perl's concept of a newline in regexp <rvtol+news@isolution.nl>
    Re: How to change Perl's concept of a newline in regexp <nospam-abuse@ilyaz.org>
        join based on conditions <mislam@spam.uiuc.edu>
    Re: join based on conditions <mritty@gmail.com>
    Re: join based on conditions <wahab@chemie.uni-halle.de>
    Re: Matching and Regular Expressions <wahab@chemie.uni-halle.de>
    Re: Matching and Regular Expressions <jgibson@mail.arc.nasa.gov>
    Re: OT: O'Reilly 'Perl CD Bookshelf' - gone for good? (Richard Williams)
    Re: Perl is worth nothing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <1usa@llenroc.ude.invalid>
    Re: Perl is worth nothing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! usenet@DavidFilmer.com
        string assignment and concatenation <justin.0511@purestblue.com>
    Re: string assignment and concatenation <dguttadauro@4ecp.com>
    Re: string assignment and concatenation <dt.news@mailnull.com>
    Re: string assignment and concatenation xhoster@gmail.com
    Re: Using Sockets connecting multiple clients <jgibson@mail.arc.nasa.gov>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 20 Nov 2006 13:39:33 -0800
From: taantle@gmail.com
Subject: Basic Pod::Html useage
Message-Id: <1164058773.910712.283560@e3g2000cwe.googlegroups.com>

I have a very basic question about the Pod::Html module.  Is this
module intended to be used in bash as a command line tool, or is it a
Perl module you can use inside of a Perl script.  I tried to create a
new object using the Pod::Html->new command and that did not work. Then
I tried pod2html() on the bash command line and that failed too.  Very
basic question but I can't continue without it!



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

Date: Mon, 20 Nov 2006 12:58:07 -0800
From: "Vronans" <vronans@nowheresville.spamwall>
Subject: Re: Can perl find strings over multiple lines?
Message-Id: <gLKdnTfPKKZ7i__YnZ2dnUVZ_t2dnZ2d@wavecable.com>

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.
>
>> What I want to do is find all the text between
>> a line beginning with "--" or "-- " and
>> ending with ")$" where '$' is, of course, the EOL char.
>>
>> I also would like to know how to find the exclusion
>> so that the output produces everything but the enclosed string above.
>> Is this possible with perl?
>
> Yes, it is.
>
> If you would like assistance with the demonstration of such abilities,
> please read and follow the Posting Guidelines for the group.  Most
> specifically, please 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;





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

Date: 20 Nov 2006 13:05:15 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Can perl find strings over multiple lines?
Message-Id: <1164056715.300444.230890@h48g2000cwc.googlegroups.com>

[removed non-existent group 'comp.lang.perl']

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.
> >
> >> What I want to do is find all the text between
> >> a line beginning with "--" or "-- " and
> >> ending with ")$" where '$' is, of course, the EOL char.
> >>
> >> I also would like to know how to find the exclusion
> >> so that the output produces everything but the enclosed string above.
> >> Is this possible with perl?
> >
> > Yes, it is.
> >
> > If you would like assistance with the demonstration of such abilities,
> > please read and follow the Posting Guidelines for the group.  Most
> > specifically, please 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.

Because absolutely no indication of any kind was given that the OP made
any attempt.

> Further more, why are some people so concerned with that in the first
> place?

Because this newsgroup is not a free tech-support system.  Everyone who
answers a post here is a volunteer. There are only so many posts that
any one person can volunteer to answer in a given day.  Most people
here, myself included, are for more inclined to offer assistance to
people who've demonstrated an attempt to solve the problem first.
Therefore, someone who makes no such demonstration is far less likely
to have their problem answered.

My comments were intended to help the OP help himself.  By making an
attempt and following the Guidelines of the group, the OP has the best
chance to actually get his problem solved.

If you want to go ahead and solve people's problems regardless of the
content of their questions, by all means, please continue to do so.  No
one will stop you, and I for one will applaud you.  ... Right up to the
moment where you say "enough is enough" and decide you can't devote any
more time to doing so.

>  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.

Nor are they supposed to.  I am of the "Teach a Man to Fish"
philosophy.  Your response helps the OP with this one particular post.
Will you necessarily be here to also answer his next one?  And the one
after that?  My response teaches him how to ask a better question so
that next time, far more people will be likely to respond to him, in
case you're not around.

Paul Lalli



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

Date: Mon, 20 Nov 2006 20:16:59 +0000
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Do I *have* to use 'OOP' to use modules?
Message-Id: <g69u00tvpok.fsf@lifelogs.com>

On 17 Nov 2006, cwilbur@chromatico.net wrote:

> Sometimes, you can get where you want to go by only turning left.
> In those cases, deciding up front that you're only going to turn
> left is not a problem.  Other times, you'll want to turn right --
> either because that's the most natural route, or because taking
> *one* right turn means you get to avoid an extra hour of driving.

There are times when an analogy is healthy and vibrant.  At other
times it has been beaten to death, like now :)

> TZ> Emacs Lisp comes to mind.  It is very useful without using OOP.
> TZ> There are many other examples.  The problem domain and
> TZ> programmer experience should make the
> TZ> OOP/procedural/functional/etc. choice.
>
> You can't do OOP in Lisp?  This is news to me.

Note I said Emacs Lisp.  I'm aware of the other flavors of Lisp and
wasn't discussing them.

> You may find that another approach (such as, if you're using Lisp, a
> functional approach) is better suited to the problem; but that is
> *not* the same thing as deciding, independently of the problem domain,
> that object oriented techniques are not to be considered.

Sure.  That's what I said, that the problem domain and the programmer
experience (meaning, experience with the methodology and with
programming in general) should make this choice.

Ted


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

Date: Mon, 20 Nov 2006 20:29:03 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: How to change Perl's concept of a newline in regexps?
Message-Id: <ejt3ee.1eg.1@news.isolution.nl>

R Krause schreef:

> I know that $/ is the input record separator. But that doesn't seem to
> affect any change in the behavior of regular expressions in normal and
> multi-line mode.

That is the wrong way around. When (line oriented) input is read, and
the proper IO-layer is used, the resulting string will have a "\n" at
the end.
See also Encode::Encoding. Compare the :crlf layer.

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Mon, 20 Nov 2006 22:25:18 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: How to change Perl's concept of a newline in regexps?
Message-Id: <ejta0e$31a3$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
R Krause
<rkrause@searstower.org>], who wrote in article <1164035405.224078.19860@m7g2000cwm.googlegroups.com>:
> > P.S.  Do not forget that (in //m mode) $ is just a shortcut for
> >       (?=\n|\z), and ^ for (?:\A|(?<=\n)).  Likewise for no //m.
> 
> Thanks. It's mostly theoretical. After all '$' and '^'  and '\Z' do
> exist for convenience as you've shown in the hint above. I was testing
> my code and it occured to me that this behavior cannot be changed. As
> far as being optimal, it is curious why Perl has certain predefined
> variables that can be changed at all since, to be fair, programmers
> should never have to modify '$/', '$\', or '$,' to perform any I/O
> operations. Yet, they exist for efficiency when needed.

I think you are wrong.  They exist mostly for backward compatibility.
These stuff should be made in channels, not in an interpreter.

Hope this helps,
Ilya


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

Date: Mon, 20 Nov 2006 13:45:13 -0600
From: Sharif Islam <mislam@spam.uiuc.edu>
Subject: join based on conditions
Message-Id: <ejt0k9$sk$1@news.ks.uiuc.edu>

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";
}


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

Date: 20 Nov 2006 11:48:43 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: join based on conditions
Message-Id: <1164052123.032692.140620@h54g2000cwb.googlegroups.com>

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";
> }

perldoc -f grep

print join ('|', grep  { $_ == 1 } $restriction1, $restriction2,
$restriction3, $restriction4), "\n";

Two notes:
1) I assume that these variable names are just samples, and not your
real data.  If that is your real code, please change those to an array
named "@restrictions", and access $restriction[0] through
$restriction[3] as need be.  Then in my code, replace the four
individual variables with @restrictions
2) If your values are really either 0 or 1, than the grep{} block can
just contain $_, rather than an explicit comparison to 1:

print join('|', grep { $_ } @restrictions), "\n";

Paul Lalli



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

Date: Mon, 20 Nov 2006 21:16:21 +0100
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: join based on conditions
Message-Id: <ejt2ob$kah$1@mlucom4.urz.uni-halle.de>

Thus spoke Sharif Islam (on 2006-11-20 20:45):
> I need to join several variables based the value (0 or 1). I only want 
> to join if the variables contain one.
> 
> $restriction1=0; $restriction2 =1; $restriction3 =1; $restriction4=1 ;
> # I don't want to include zero in the join, how??
> 

{
  local $"='|' ;
  print "@{[grep $_,($restriction1,$restriction2,$restriction3,$restriction4)]}";
}


Regards

Mirco



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

Date: Mon, 20 Nov 2006 20:39:23 +0100
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Matching and Regular Expressions
Message-Id: <ejt0j3$jm3$1@mlucom4.urz.uni-halle.de>

Thus spoke deadpickle (on 2006-11-20 19:40):
> Here is a quick code I came up with:
> X  A  F 0 US
> ND DEVILS LAKE      KDVL  DVL   72757  48 07N  098 55W  443   X
>   W    7 US
> ND DEVILS LAKE      KP11  P11   72758  48 07N  098 55W  443   X
>   W    7 US
> ND DICKINSON        KDIK  DIK          46 48N  102 48W  788   X     U

The problem here is, there are missing fields -- otherwise
this would be simple split-thing.

I guess from your code that your data got garbled and looks like:

!23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
!
NORTH DAKOTA       24-JUN-05
CD  STATION         ICAO  IATA  SYNOP   LAT     LONG   ELEV   M  N  V U  A  C
ND BISMARCK         KBIS  BIS   72764  46 46N  100 45W  505   X  X  U X  A  F 0 US
ND DEVILS LAKE      KDVL  DVL   72757  48 07N  098 55W  443   X          W    7 US
ND DEVILS LAKE      KP11  P11   72758  48 07N  098 55W  443   X          W    7 US
ND DICKINSON        KDIK  DIK          46 48N  102 48W  788   X     U    A    6 US
ND FARGO            KFAR  FAR   72753  46 56N  096 49W  277   X     U    A    1 US


If this would be a column format (only whitespaces, no tabs and stuff),
this would be easy to do with substr() or the like.

But - if anything is free and only text segments count, then you
have to write a regex, that models the data and extracts the info
you need.

Say, we want to pull out main numbers into a hash, this would be the regex:

---- 8< ----

my $STATIONS = 'KBIS|KDVL';

my $format=qr/($STATIONS)    .+        # station name
              (\d{5}|\D{5})      \s+   # synop
              (\d+) \s+ (\d+) \w \s+   # latitude
              (\d+) \s+ (\d+) \w \s+   # longitude
              (\d+)/x;                 # elevation

---- 8< ----

then you can extract the data in a loop, as you did:

---- 8< ----

my @results;

while (<ID>) {
   push @results, { NAME=>$1, SYNOP=>$2, LAT=>"$3.$4", LONG=>"$5.$6", ELEV=>$7 }
      if /$format/;
}

---- 8< ----

All stuff is now in the hash array, now lets extract it:

---- 8< ----

for my $st (@results) {
   print "$_ = $st->{$_} " for keys %{$st};
   print "\n";
}

---- 8< ----

This will actually print one record with all the data from
the record above, eg.:

  SYNOP = 72764 NAME = KBIS LAT = 46.46 ELEV = 505 LONG = 100.45
  SYNOP = 72757 NAME = KDVL LAT = 48.07 ELEV = 443 LONG = 098.55


What do you need that for and which data is really needed?

Is this a column format?

Regards

Mirco


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

Date: Mon, 20 Nov 2006 12:58:24 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Matching and Regular Expressions
Message-Id: <201120061258242441%jgibson@mail.arc.nasa.gov>

In article <1164041080.502447.280890@f16g2000cwb.googlegroups.com>,
deadpickle <deadpickle@gmail.com> wrote:

> I need to search a txt document for several strings and then report
> them in an array. The source document looks as follows:
> 
> AR FLIPPIN (AWOS)   KFLP  FLP          36 17N  092 35W  219   X
>   W    7 US
> AR FORT SMITH       KFSM  FSM   72344  35 20N  094 22W  140   X     U
>   A    3 US
> AR SLATINGTON MTN.  KSRX  SRX          35 17N  094 22W  195      X
>        8 US
> AR HARRISON         KHRO  HRO          36 16N  093 09W  417   X     T
>   A    6 US
> AR HOT SPRINGS      KHOT  HOT          34 29N  093 06W  162   X     T
>   A    6 US
> AR JONESBORO        KJBR  JBR          35 50N  090 39W   79   X     T
>   A    6 US
> AR LITTLE ROCK      KLIT  LIT          34 44N  092 14W   79   X     U
>   A    0 US
> 
> The string I want to search for is KFSM and  KJBR and I want the
> following numerical values reported to an array. I started to try and
> make this but I dont understand regular expressions very well. Thanks
> for the help.
> 

In addition to Sherm's advice, for fixed-format lines such as these I
would consider using the unpack function to extract the individual
fields.

perlddoc -f unpack
perldoc -f pack   (for the template rule elements)


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

Date: 20 Nov 2006 19:21:32 GMT
From: rdwillia@anon.example.net (Richard Williams)
Subject: Re: OT: O'Reilly 'Perl CD Bookshelf' - gone for good?
Message-Id: <ejsv7s$2d1$1@newsserver.cilea.it>

In article <Xns98807A896BEBEcastleamber@130.133.1.4>,
John Bokma  <john@castleamber.com> wrote:
>rdwillia@anon.example.net (Richard Williams) wrote:

>CHM does the same. What's in my not so humble opinion really crazy is 
>that *buying* an e-book in CHM format is next to impossible (if not, 
>please give me a site). Moreover, e-books have been protected, so I am 
>afraid it's impossible to convert, say, LIT to CHM (which I understand 
>should be no big deal), or LIT to PDF.

Certainly I'd love to see more stuff in unrestricted formats, just as the 
Bookshelves were. My preference would still be plain HTML, which is 
readable everywhere, even on my phone or (obviously) with a text mode 
browser like lynx.

>Also, I forgot the actual price, but getting a book by mail here (I live 
>in Mexico) is about 1/4th of the price of a book. Books are not cheap, 
>and sending them neither (and it takes 2-5 weeks). I am all for e-books, 
>withouth DRM (silly, people can remove that in no time, waste of money).

I'd be happy so see DRM-free downloads replacing the Bookshelves, but 
clearly O'Reilly isn't likely to go that route, either. It's a particular 
shame that it's no longer possible to point to them as a well-known 
publisher making a profit from selling major DRM-free technical ebooks 
(except presumably the 'Rough Cuts' and 'Short Cuts').

>Really, like many others, you're looking in the wrong places. The real 
>thing happens on Usenet and Bittorrent.

Sure, but people looking for pirated books in places like this know 
exactly what they're doing. It's quite possible to run across the pirated 
Bookshelf volumes purely by accident and, if you're not familiar with the 
CDs and don't look too closely, without even realising they aren't 
legitimate sources (I'm pretty sure this is true of some of the academic 
sites that reference them). The FIRST Google hit for 'Perl cookbook', 
'Perl in a nutshell', 'Perl for system administration', 'Perl CD' or 'CD 
bookshelf' is a Ukrainian site (presumably as untouchable as allofmp3 in 
Russia) that hosts over 60 O'Reilly titles copied directly from the 
Bookshelves. Pirated copies of 'Programming Perl' and 'Learning Perl' are 
also in the top five Google hits for these titles. I can't think of any 
other pirated texts that are this prominent and accessible, and wouldn't 
be at all suprised if (for the Perl books at least) many more people are 
reading them on these sites than on Safari (let alone going to the trouble 
of downloading the torrents). But obviously nobody knows the real figures. 
No one seems to have gone to the trouble of making the non-Bookshelf 
volumes available this way (which would involve a bit more work - the 
Bookshelves are already 'canned websites').

>CPAN, perldoc, and the hundreds and hundreds of well written articles, a 
>lot standing far, far above some books I bought. Also documentation that 
>comes with programs seem to have improved. In the '90s this was often 
>"use the source, Luke".

Even so, the commercial texts are filling a need (e.g. for extended 
explanations and a comprehensice collection of useful recipes) that isn't 
met by the online documentation, and plenty of people are still buying (or 
otherwise obtaining) the O'Reilly books (if they weren't, we wouldn't be 
having this discussion, and the pirated books wouldn't score so highly in 
the Google ranking).

Richard.


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

Date: Mon, 20 Nov 2006 21:07:39 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl is worth nothing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Message-Id: <Xns9881A42EF2D39asu1cornelledu@127.0.0.1>

"robertospara" <robertospara@gmail.com> wrote in 
news:1164034280.226062.270460@b28g2000cwb.googlegroups.com:

> 
> Ciao, nara, bye.
> 

On that, we agree. Bye bye ...
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: 20 Nov 2006 14:22:08 -0800
From: usenet@DavidFilmer.com
Subject: Re: Perl is worth nothing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Message-Id: <1164061328.521822.67890@h54g2000cwb.googlegroups.com>

robertospara wrote:
> Perl is worth nothing!

Well, that's about what you paid for it, so why complain?  Go use Ruby.

-- 
David Filmer (http://DavidFilmer.com)



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

Date: Mon, 20 Nov 2006 19:04:54 -0000
From: Justin C <justin.0511@purestblue.com>
Subject: string assignment and concatenation
Message-Id: <slrnem3v2m.4su.justin.0511@stigmata.purestblue.com>

#!/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.


	Justin.

-- 
Justin C by the sea.


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

Date: 20 Nov 2006 12:58:02 -0800
From: "Dean G." <dguttadauro@4ecp.com>
Subject: Re: string assignment and concatenation
Message-Id: <1164056282.120134.76240@h54g2000cwb.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 ) ;
>     }
> }
>
>
> 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.

What does your output look like ?

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

Dean G.



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

Date: Mon, 20 Nov 2006 13:12:11 -0800
From: dt <dt.news@mailnull.com>
Subject: Re: string assignment and concatenation
Message-Id: <45620da6$0$21183$88260bb3@free.teranews.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 ) ;

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.

Newer versions of File::Copy export a move() function.

dt

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



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

Date: 20 Nov 2006 23:03:41 GMT
From: xhoster@gmail.com
Subject: Re: string assignment and concatenation
Message-Id: <20061120180344.554$Ul@newsreader.com>

justin.news@purestblue.com wrote:
>
> 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.

It sounds to me like you have "\r" (aka ^M) or other special characters in
your csv file.  When you print such strings to your terminal, it causes
weird things to happen.  Instead of just printing to the sceen, redirect
output to a file and open it in a good text editor.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Mon, 20 Nov 2006 12:52:07 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Using Sockets connecting multiple clients
Message-Id: <201120061252079849%jgibson@mail.arc.nasa.gov>

In article <1164024840.408437.312890@h54g2000cwb.googlegroups.com>,
<"sujay.tukai@gmail.com"> wrote:

> I am trying to establish a socket connection between one server and
> multiple clients....

You are using the UDP protocol, which does not create connections.
Socket objects of this protocol may be used to send or receive
individual datagrams between one host and another. See 'perldoc
perlipc' and search for 'UDP: Message Passing' for more info.

You can use the select statement to query whether or not datagrams have
been received from a number of remote hosts, asynchronously.


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

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


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