[30991] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2236 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 25 21:09:43 2009

Date: Wed, 25 Feb 2009 18:09:12 -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           Wed, 25 Feb 2009     Volume: 11 Number: 2236

Today's topics:
        bigint vs. bignum <yakovlev@hotmail.com>
    Re: bigint vs. bignum xhoster@gmail.com
    Re: debugging on stdout <ben@morrow.me.uk>
    Re: debugging on stdout <no_th@nks.org>
        Email Purge Again <tod@asgweb.net>
    Re: Email Purge Again <tim@burlyhost.com>
    Re: Email Purge Again <tim@burlyhost.com>
    Re: Email Purge Again <tod@asgweb.net>
    Re: Email Purge Again <tim@burlyhost.com>
    Re: Email Purge Again <tim@burlyhost.com>
    Re: Email Purge Again <tim@burlyhost.com>
    Re: Email Purge Again <tim@burlyhost.com>
    Re: Email Purge Again <ben@morrow.me.uk>
    Re: Email Purge Again sln@netherlands.com
    Re: Trying to convert small C++ subroutine (by Peter We <tzz@lifelogs.com>
    Re: Trying to convert small C++ subroutine (by Peter We (Jens Thoms Toerring)
    Re: very simple file stitching problem <brianwilliambishop@gmail.com>
    Re: very simple file stitching problem <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 25 Feb 2009 16:02:03 -0800 (PST)
From: Alex <yakovlev@hotmail.com>
Subject: bigint vs. bignum
Message-Id: <a77a22bb-374c-4892-83ec-a8366f1addeb@q30g2000vbn.googlegroups.com>

Hello, I'm new to Perl

I have a small program, which uses only (big) integers, but works
differently with "use bigint" and "use bignum". Can you please explain
why?

sub Next($)
{
  my $var = shift;
  my $tst = $var % 2;
  return ($tst == 0) ? $var / 2 : $var * 3 + 1;
}

my $n = 2 ** 1000 - 1;
my $counter = 0;

while (1)
{
  $n = Next($n);
  if ($n == 1)
  {
    print("counter = ", $counter, "\n");
    last;
  }
  $counter++;
}

Thank you in advance
Alex


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

Date: 26 Feb 2009 01:21:08 GMT
From: xhoster@gmail.com
Subject: Re: bigint vs. bignum
Message-Id: <20090225201951.346$H0@newsreader.com>

Alex <yakovlev@hotmail.com> wrote:
> Hello, I'm new to Perl
>
> I have a small program, which uses only (big) integers, but works
> differently with "use bigint" and "use bignum". Can you please explain
> why?
>
> sub Next($)
> {
>   my $var = shift;
>   my $tst = $var % 2;
>   return ($tst == 0) ? $var / 2 : $var * 3 + 1;

use bignum turns on upgrading.

When the division by 2 happens, the BigInt upgrades to BigFloat.  It
doesn't look to see if the division results in an integer before
upgrading--it just does it.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Wed, 25 Feb 2009 21:47:44 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: debugging on stdout
Message-Id: <0tqg76-5p11.ln1@osiris.mauzo.dyndns.org>


Quoth tmcd@panix.com:
> In article <ldhe76-1cp.ln1@osiris.mauzo.dyndns.org>,
> Ben Morrow  <ben@morrow.me.uk> wrote:
> >I would avoid using Open2 directly in favour of IPC::Run, which has a
> >much cleaner interface and is more portable to systems like Win32.
> 
> One review says <http://cpanratings.perl.org/dist/IPC-Run>
> 
>     In words of the author of IPC::Run
>     > I would personally recommend IPC::Cmd rather than IPC::Run right now.
>     > It seems more stable and well-supported.
> 
> Is there a reason to go for IPC::Run instead of IPC::Cmd?

IPC::Cmd doesn't do the same thing? In particular, it doesn't have
open2-like functionality.

Ben



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

Date: Thu, 26 Feb 2009 00:19:28 GMT
From: mike <no_th@nks.org>
Subject: Re: debugging on stdout
Message-Id: <m38wnu3v8v.fsf@localhost.localdomain>


I appreciate your time and great perl tips, thanks.


> I will ask you again: why on earth are you keeping the offset in a file
> at all? Just keep it in a variable.

unless you mean keep it in a var only while the script is running, I have
stacks of instructional videos and using respectively named text files
allows me to have mplayer automatically seek to the position I last left
off at when I reload a vid that has such a file (and obv if it doesn't my
script creates one for it).  there's a 15s loop which repeatedly updates
that file w/current vid position while the video remains loaded or
running.

to give credit, I got the idea from a very handy mplayer-resume php script
where I learned one can 'talk' to mplayer.  but after using his script
briefly felt it was too limited so made my own.


> > 5. mplayer whether started with a vid arg or not appears to start with two
> >    consecutive pids where the second indicates that a video is loaded or
> >    running - to guarantee I can find mplayer's responses to my queries I
> >    throw away everything up to "Starting..."; to guarantee I'll find 
> >    "Starting..." I don't look for it until the "L" in ps shows up.
> 
> You shouldn't need to mess about with ps: just read from mplayer's
> output until it gets to "Starting...".


obv I'm just sort of fumbling through this but how I have it now is, my
script needs both video filename and current time position and to get
either of them (at various places) I do:

	$video = vid_filename_query();
and/or
	print SEEK_FH vid_position_query();


# -------------------
# ask mplayer current vid's filename and return it (never includes its path):
sub vid_filename_query {
   writer->print("pausing_keep get_file_name\n");
   $_ = <reader>;
   /ANS_FILENAME=\'(.*)\'/;
   return $1;
}

# ask mplayer where current vid is positioned (return val is "seconds"):
sub vid_position_query {
   writer->print("pausing_keep get_time_pos\n");
   $_ = <reader>;
   /ANS_TIME_POSITION=(.*)/;
   return $1;
}
# -------------------


"pages locked in memory" for mplayer's pid (or "Starting..." for that
matter) appear only once a video is loaded.  until that happens mplayer
ignores or fails to respond to the specific things I ask it (obv "get_*"
would be meaningless if no video is loaded; and mplayer may be accepting a
meaningless instruction and simply dropping it, I don't know).

but as you can see by my writer/<reader> combos, if I try one when no
video is loaded, and mplayer is not going to respond, then <reader> hangs
waiting for something that isn't coming.

so I test for ps "L" (coincidental to "Starting...") to inform my script
whether or not mplayer is going to respond before sending it an
instruction (and since ps "L" is valid whether vid is running or just
loaded but stopped, I only need to do this pid chk once/video).

so whether or not I just use <reader> to scan up to "Starting...", I can't
know it won't hang not finding it if I don't first test for ps "L". imm :)


-- 


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

Date: Wed, 25 Feb 2009 14:20:48 -0800 (PST)
From: perl <tod@asgweb.net>
Subject: Email Purge Again
Message-Id: <ccc2f10c-9cd9-4dac-9506-03bf1907a637@v15g2000yqn.googlegroups.com>

Ok, thanks for the helpful responses from my last post. I modified the
code with 2 different suggestions. I'm not using strict. Any ideas?

With this code.. %emails = map { chomp; $_, 1 } <$list>;
 I get this error
Can't modify concatenation (.) or string in scalar assignment at
email.cgi line 535, near "<$list>;"

With this code: $emails{lc $_} = 1 if ! exists $emails{lc $_};
 I get this error
Can't modify concatenation (.) or string in scalar assignment at
email.cgi line 534, near "1 if"

Here is the whole routine...
my $list2 = "$userpath/files/$list";
my %emails;
open(my $list, '<', $list2)
or error("Open failed $list2 $!");
while (<$list>) {
       chomp if defined;
       next if /^\s*$/;
       $emails{lc $_} = 1 if ! exists $emails{lc $_};
       #%emails = map { chomp; $_, 1 } <$list>;
}

close($list) or warn $!;


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

Date: Wed, 25 Feb 2009 15:08:56 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Email Purge Again
Message-Id: <cckpl.32198$uG1.15038@newsfe16.iad>

perl wrote:

> Ok, thanks for the helpful responses from my last post. I modified the
> code with 2 different suggestions. I'm not using strict. Any ideas?
> 
> With this code.. %emails = map { chomp; $_, 1 } <$list>;
>  I get this error
> Can't modify concatenation (.) or string in scalar assignment at
> email.cgi line 535, near "<$list>;"
> 
> With this code: $emails{lc $_} = 1 if ! exists $emails{lc $_};
>  I get this error
> Can't modify concatenation (.) or string in scalar assignment at
> email.cgi line 534, near "1 if"
> 
> Here is the whole routine...
> my $list2 = "$userpath/files/$list";
> my %emails;
> open(my $list, '<', $list2)
> or error("Open failed $list2 $!");
> while (<$list>) {
>        chomp if defined;
>        next if /^\s*$/;
>        $emails{lc $_} = 1 if ! exists $emails{lc $_};
>        #%emails = map { chomp; $_, 1 } <$list>;
> }
> 
> close($list) or warn $!;

The above code shouldn't give that error.  The code you've pasted above
must not be the exact code you're trying to run.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Wed, 25 Feb 2009 15:12:56 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Email Purge Again
Message-Id: <Zfkpl.32302$uG1.2397@newsfe16.iad>

Tim Greer wrote:

> perl wrote:
> 
>> Ok, thanks for the helpful responses from my last post. I modified
>> the code with 2 different suggestions. I'm not using strict. Any
>> ideas?
>> 
>> With this code.. %emails = map { chomp; $_, 1 } <$list>;
>>  I get this error
>> Can't modify concatenation (.) or string in scalar assignment at
>> email.cgi line 535, near "<$list>;"
>> 
>> With this code: $emails{lc $_} = 1 if ! exists $emails{lc $_};
>>  I get this error
>> Can't modify concatenation (.) or string in scalar assignment at
>> email.cgi line 534, near "1 if"
>> 
>> Here is the whole routine...
>> my $list2 = "$userpath/files/$list";
>> my %emails;
>> open(my $list, '<', $list2)
>> or error("Open failed $list2 $!");
>> while (<$list>) {
>>        chomp if defined;
>>        next if /^\s*$/;
>>        $emails{lc $_} = 1 if ! exists $emails{lc $_};
>>        #%emails = map { chomp; $_, 1 } <$list>;
>> }
>> 
>> close($list) or warn $!;
> 
> The above code shouldn't give that error.  The code you've pasted
> above must not be the exact code you're trying to run.

Actually, looking again, you have $list in both the:

my $list2 = "$userpath/files/$list";

As well as for the $fh.  Did you mean to use the same name for both (I
doubt it)?  Also, what is the content of the file you're opening? 
Perhaps try adding a check (which you'd want to do anything) in some
attempt to verify the value at least appears to be a valid email.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Wed, 25 Feb 2009 15:46:47 -0800 (PST)
From: perl <tod@asgweb.net>
Subject: Re: Email Purge Again
Message-Id: <b8abda7a-6b5e-4de9-87d3-489646cb7169@j35g2000yqh.googlegroups.com>

Great! That fixed the error. BUT.. it's not eliminating duplicates...?
my $list2 = "$userpath/files/$list";
my %emails;
open(my $USERS, '<', $list2)
or error("Open failed $list2 $!");
while (<$USERS>) {
       chomp if defined;
       next if /^\s*$/;
       $emails{lc $_} = 1 if ! exists $emails{lc $_};
       #%emails = map { chomp; $_, 1 } <$USERS>;

}

close($USERS) or warn $!;


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

Date: Wed, 25 Feb 2009 15:50:40 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Email Purge Again
Message-Id: <lPkpl.32331$uG1.9051@newsfe16.iad>

perl wrote:

> while (<$list>) {
> chomp if defined;
> next if /^\s*$/;
> $emails{lc $_} = 1 if ! exists $emails{lc $_};
> #%emails = map { chomp; $_, 1 } <$list>;
> }

Also, you don't need to put:

%emails = map {chomp; $_, 1 } <$list>;

in the while() loop -- it's just another method of doing the while/for.

In other words, either do:

while (<$list>) {
 chomp if defined;
 next if /^\s*$/;
 $emails{lc $_} = 1 if ! exists $emails{lc $_};
}

Or do:

%emails = map {chomp; lc, 1 } <$list>;

There are other ways, too.

Speaking of, you should do some check to see that the email appears to
be valid, and there are tools that can do the checking for you (so this
is an example, look for the right tool) and do something like:

next if !/^[-.\w]+\@[-\w.]+\.[a-z]{2,5}$/i;

in the while loop before $emails{lc $_}.

Or, for map, maybe something like:

        %emails = map {
                        chomp;
                        (/^[-.\w]+\@[-\w.]+\.[a-z]{2,5}$/i)
                        ? lc : '', 1
        } <$list>;

Again, just quick examples based on the code you're trying to use above
(not necessarily the best method).  Besides, both the original and
modified map methods will create an empty hash key, which you probably
don't want, so if you use that method, account for that to prevent it
from happening.  The above is something I'd do (but that's just off the
top of my head for an example and some people may disagree with it), so
be sure to understand it instead of just throwing code into it, because
it might not be what you want or need (this is just based on your code
examples).
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Wed, 25 Feb 2009 15:53:43 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Email Purge Again
Message-Id: <bSkpl.32335$uG1.1698@newsfe16.iad>

perl wrote:

> Great! That fixed the error. BUT.. it's not eliminating duplicates...?
> my $list2 = "$userpath/files/$list";
> my %emails;
> open(my $USERS, '<', $list2)
> or error("Open failed $list2 $!");
> while (<$USERS>) {
>        chomp if defined;
>        next if /^\s*$/;
>        $emails{lc $_} = 1 if ! exists $emails{lc $_};
>        #%emails = map { chomp; $_, 1 } <$USERS>;
> 
> }
> 
> close($USERS) or warn $!;

How are you seeing the duplicates?  That above should account for it,
unless perhaps you have something creating keys that are similar.  That
hash should only have unique keys (it can't actually have duplicate key
names).  How did you determine it's not eliminating them?  By you
printing the hash keys? I assume not.  Or by you re-checking the file
that should be updated with the now unique addresses?  I'm thinking
it's how you're updating/writing to the file after the fact and an
issue with your code there.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Wed, 25 Feb 2009 15:56:55 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Email Purge Again
Message-Id: <bVkpl.32339$uG1.19744@newsfe16.iad>

Tim Greer wrote:

> perl wrote:
> 
>> while (<$list>) {
>> chomp if defined;
>> next if /^\s*$/;
>> $emails{lc $_} = 1 if ! exists $emails{lc $_};
>> #%emails = map { chomp; $_, 1 } <$list>;
>> }
> 
> Also, you don't need to put:
> 
> %emails = map {chomp; $_, 1 } <$list>;
> 
> in the while() loop -- it's just another method of doing the
> while/for.
> 
> In other words, either do:
> 
> while (<$list>) {
>  chomp if defined;
>  next if /^\s*$/;
>  $emails{lc $_} = 1 if ! exists $emails{lc $_};
> }
> 
> Or do:
> 
> %emails = map {chomp; lc, 1 } <$list>;
> 
> There are other ways, too.
> 
> Speaking of, you should do some check to see that the email appears to
> be valid, and there are tools that can do the checking for you (so
> this is an example, look for the right tool) and do something like:
> 
> next if !/^[-.\w]+\@[-\w.]+\.[a-z]{2,5}$/i;
> 
> in the while loop before $emails{lc $_}.
> 
> Or, for map, maybe something like:
> 
>         %emails = map {
>                         chomp;
>                         (/^[-.\w]+\@[-\w.]+\.[a-z]{2,5}$/i)
>                         ? lc : '', 1
>         } <$list>;
> 
> Again, just quick examples based on the code you're trying to use
> above
> (not necessarily the best method).  Besides, both the original and
> modified map methods will create an empty hash key, which you probably
> don't want, so if you use that method, account for that to prevent it
> from happening.  The above is something I'd do (but that's just off
> the top of my head for an example and some people may disagree with
> it), so be sure to understand it instead of just throwing code into
> it, because it might not be what you want or need (this is just based
> on your code examples).

Hmm, my last post never showed up on my ISP's usenet server.  I said
that you don't need to backwack @ in the regular expression (I was busy
with something else and wasn't thinking).
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Wed, 25 Feb 2009 15:55:43 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Email Purge Again
Message-Id: <zXkpl.32341$uG1.6509@newsfe16.iad>

Tim Greer wrote:

> next if !/^[-.\w]+\@[-\w.]+\.[a-z]{2,5}$/i;
                   ^^^
And, sorry, you don't need to deference/backwack for @ in the regex.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Wed, 25 Feb 2009 23:53:45 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Email Purge Again
Message-Id: <992h76-sdh.ln1@osiris.mauzo.dyndns.org>


Quoth perl <tod@asgweb.net>:
> Great! That fixed the error. BUT.. it's not eliminating duplicates...?

At the moment it's not doing anything except populating a hash. If you
want it to do more than that, you need to take the %emails hash and do
something with it.

> my $list2 = "$userpath/files/$list";
> my %emails;
> open(my $USERS, '<', $list2)
> or error("Open failed $list2 $!");
> while (<$USERS>) {
>        chomp if defined;

That 'if defined' is redundant. If $_ is undefined, the while loop will
have terminated and you won't get there.

Ben



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

Date: Thu, 26 Feb 2009 01:38:52 GMT
From: sln@netherlands.com
Subject: Re: Email Purge Again
Message-Id: <i7sbq499daed947stikmmkf6s2rqjiha4l@4ax.com>

On Wed, 25 Feb 2009 14:20:48 -0800 (PST), perl <tod@asgweb.net> wrote:

>Ok, thanks for the helpful responses from my last post. I modified the
>code with 2 different suggestions. I'm not using strict. Any ideas?
>
>With this code.. %emails = map { chomp; $_, 1 } <$list>;
> I get this error
>Can't modify concatenation (.) or string in scalar assignment at
>email.cgi line 535, near "<$list>;"
>
>With this code: $emails{lc $_} = 1 if ! exists $emails{lc $_};
> I get this error
>Can't modify concatenation (.) or string in scalar assignment at
>email.cgi line 534, near "1 if"
>
>Here is the whole routine...
>my $list2 = "$userpath/files/$list";
>my %emails;
>open(my $list, '<', $list2)
>or error("Open failed $list2 $!");
>while (<$list>) {
>       chomp if defined;
  don't need, won't get here if not defined, plus why take off \n ?
>       next if /^\s*$/;
  don't need, leaves everything past the first group of white spaces
>       $emails{lc $_} = 1 if ! exists $emails{lc $_};
  don't need, why check for existence?
>       #%emails = map { chomp; $_, 1 } <$list>;
>}
>
>close($list) or warn $!;

If you trust your email lists for validity, the below
grabs just the email from the line and adds it as a key.
Dosen't matter if it already exists, just asigning it a value
of 1.

-sln

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

use strict;
use warnings;

my %emails;

while (<DATA>) {
	next if !(/^\s*(.*?)\s*$/ && length $1);
	$emails{lc $1} = 1;
}
# display key/vals (but you only want the keys probably)
while( my ($key,$val) = each %emails) {
	print "$key = $val\n";
}

__DATA__

   aasdf 	

this is test   
line 2   
line 3   
junk@Microsoft.com
	


				  




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

Date: Wed, 25 Feb 2009 15:16:16 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Trying to convert small C++ subroutine (by Peter Weinberger) to Perl
Message-Id: <86bpsqw733.fsf@lifelogs.com>

On 24 Feb 2009 09:11:20 GMT jt@toerring.de (Jens Thoms Toerring) wrote: 

JTT>     for ( split //, $s ) {
JTT>        $hash = ( $hash << 4 ) + ord $_;
 ...
JTT> The Perl version as it is will happily accept e.g. Unicode
JTT> characters and then the result will differ from the C/C++ version!

An easy way to fix that is to replace the lines with

for ( unpack "C*", $s) {
        $hash = ( $hash << 4 ) + $_;

which will probably also be faster, a nice property for a hashing
function (unpack over split, and no ord() call).

Ted


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

Date: 25 Feb 2009 21:52:37 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: Trying to convert small C++ subroutine (by Peter Weinberger) to Perl
Message-Id: <70lst5Fds35tU1@mid.uni-berlin.de>

Ted Zlatanov <tzz@lifelogs.com> wrote:
> On 24 Feb 2009 09:11:20 GMT jt@toerring.de (Jens Thoms Toerring) wrote: 

> JTT>     for ( split //, $s ) {
> JTT>        $hash = ( $hash << 4 ) + ord $_;
> ...
> JTT> The Perl version as it is will happily accept e.g. Unicode
> JTT> characters and then the result will differ from the C/C++ version!

> An easy way to fix that is to replace the lines with

> for ( unpack "C*", $s) {
>         $hash = ( $hash << 4 ) + $_;

> which will probably also be faster, a nice property for a hashing
> function (unpack over split, and no ord() call).

Is a char guaranteed to be unsigned in C++? I'm only sure it
isn't in C, so the behaviour of the original function (which
could be C or C++) wouldn't be well-defined at least in C for
anything than 7-bit (ASCII) chars as the input.

Using unpack() is definitely more elegant (and more in the
spirit of the original function should there be Unicode chars
in the string). All one would need to know is if "C*" or "c*"
would have to be used with unpack().

                            Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de


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

Date: Wed, 25 Feb 2009 13:38:24 -0800 (PST)
From: Brian <brianwilliambishop@gmail.com>
Subject: Re: very simple file stitching problem
Message-Id: <dc828f26-698c-4c69-8b65-78494bf48e67@q11g2000vbn.googlegroups.com>

Thank you all for your rapid and gracious replies.

On Feb 25, 4:01=A0pm, "John W. Krahn" <some...@example.com> wrote:
> Brian wrote:
> > it may not be obvious from this novitiate perl code below, but i am
> > trying to add the lines of one file to the lines of another file to
> > create a third file. =A0the lines in each file are semantically related=
,
> > and will always 'line up.'
>
> > use strict;
>
> use warnings;
>
> > $ARGV[2] or die "Usage: perl stitch2files.pl [infile1] [infile2]
> > [outfile] - attaches all values from the list of equal values to ea
> > line of another list ";
>
> @ARGV =3D=3D 3 or die "Usage: ...";
>
> > my $infile1 =3D $ARGV[0];
> > my $infile2 =3D $ARGV[1];
> > my $outfile =3D $ARGV[2];
>
> my ( $infile1, $infile2, $outfile ) =3D @ARGV;
>
> > open INFILE1, $infile1 or die "Couldn't open input file: $infile1\n";
> > open INFILE2, $infile2 or die "Couldn't open input file: $infile2\n";
> > open OUTPUTFILE, ">$outfile" or die "Couldn't open output file:
> > $outfile\n";
>
> You should include the $! variable in the error message(s) so you know
> why open failed.
>
> > my @data1 =3D <INFILE1>;
> > my @data2 =3D <INFILE2>;
> > close INFILE1;
> > close INFILE2;
>
> > my $sLine;
> > my $iLineCount =3D 0;
> > foreach $sLine (@data1)
>
> foreach my $sLine (@data1)
>
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0my $sAddLine =3D "";
> > =A0 =A0 =A0 =A0 =A0 =A0$iLineCount =3D $iLineCount + 1;
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $iLineCount++;
>
> > =A0 =A0 =A0 =A0 =A0 =A0chomp($sLine);
> > =A0 =A0 =A0 =A0 =A0 =A0$sAddLine =3D @data2[$iLineCount];
>
> You have just incremented $iLineCount so it will miss the first element
> of @data2 and try to read one element past the last element of @data2.
> Also, you are using an array slice when you should be using a scalar,
> which perl would have warned you about if you had used the warnings pragm=
a.
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $sAddLine =3D $data2[$iLineCount];
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $iLineCount++;
>
> Or simply:
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $sAddLine =3D $data2[$iLineCount++];
>
> > =A0 =A0 =A0 =A0 =A0 =A0$sLine =3D $sLine . "," . $sAddLine;
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $sLine .=3D ",$sAddLine";
>
> > =A0 =A0 =A0 =A0 =A0 =A0printf $sLine;
>
> You are using printf which treats its first argument as a format string
> so if you have any '%' characters in $sLine this will not work. =A0Just
> use print:
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 print $sLine;
>
>
>
> > =A0 =A0 =A0 =A0 =A0 =A0print OUTPUTFILE $sLine;
> > =A0 =A0 =A0 =A0 }
>
> > close OUTPUTFILE;
>
> > exit(0);
>
> > problem is, i can't seem to address the individual items in the array
> > formed from the second file, from within a loop designed to process
> > each item in the first array (formed from the first file).
>
> > the error message, while understandable, seems unavoidable:
>
> > Use of uninitialized value in concatenation (.) or string at
> > stitch2files.pl lin
> > e 28.
>
> John
> --
> Those people who think they know everything are a great
> annoyance to those of us who do. =A0 =A0 =A0 =A0-- Isaac Asimov



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

Date: Wed, 25 Feb 2009 21:49:29 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: very simple file stitching problem
Message-Id: <90rg76-5p11.ln1@osiris.mauzo.dyndns.org>


Quoth Brian <brianwilliambishop@gmail.com>:
> it may not be obvious from this novitiate perl code below, but i am
> trying to add the lines of one file to the lines of another file to
> create a third file.  the lines in each file are semantically related,
> and will always 'line up.'

What's wrong with paste(1)?

Ben



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

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 V11 Issue 2236
***************************************


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