[23838] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6041 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 29 22:11:42 2004

Date: Thu, 29 Jan 2004 19:06:13 -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: 6041

Today's topics:
    Re: problem with 'or' statement <tadmc@augustmail.com>
    Re: problem with 'or' statement $_@_.%_
    Re: problem with 'or' statement <syscjm@gwu.edu>
    Re: problem with 'or' statement <tadmc@augustmail.com>
    Re: problem with 'or' statement <aolblowz@yahoo.com>
    Re: problem with 'or' statement <uri@stemsystems.com>
    Re: problem with 'or' statement <tadmc@augustmail.com>
    Re: problem with 'or' statement <bik.mido@tiscalinet.it>
    Re: problem with 'or' statement <bik.mido@tiscalinet.it>
    Re: problem with 'or' statement <aolblowz@yahoo.com>
    Re: problem with 'or' statement <bik.mido@tiscalinet.it>
        Problem with MIME::Entity <Guru03@despammed.com>
    Re: Problem with MIME::Entity <theaney@cablespeed.com>
    Re: Problem with table in the module HTML::TextToHtml <yas_okamoto@hotmail.com>
    Re: process ids <jgibson@mail.arc.nasa.gov>
        Programmer's notebook: static variables in Perl <irving_kimura@lycos.com>
    Re: Programmer's notebook: static variables in Perl <invalid-email@rochester.rr.com>
    Re: Programmer's notebook: static variables in Perl (Jay Tilton)
    Re: Programmer's notebook: static variables in Perl <tadmc@augustmail.com>
    Re: Programmer's notebook: static variables in Perl <nobull@mail.com>
    Re: Programmer's notebook: static variables in Perl (Jay Tilton)
    Re: Randomise splitting file into two new files ctcgag@hotmail.com
    Re: Randomise splitting file into two new files <bumble@what.the.heck>
    Re: Randomise splitting file into two new files <krahnj@acm.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 21 Jan 2004 08:08:28 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: problem with 'or' statement
Message-Id: <slrnc0t1us.6l3.tadmc@magna.augustmail.com>

lucas <aolblowz@yahoo.com> wrote:

> Subject: problem with 'or' statement


Did you mean to mention the "or" operator somewhere in your post?

If not, then why the misleading choice of Subject?


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


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

Date: Wed, 21 Jan 2004 15:38:00 GMT
From: $_@_.%_
Subject: Re: problem with 'or' statement
Message-Id: <s1xPb.3929$ro4.1019@nwrdny02.gnilink.net>

> is there some way i can write:
> if (some_routine()) { do_this(); and_that(); }
> 
> like so: 
> some_routine() || { do_this(); and_that(); }
> 
> the reason is, i have a bunch of code that would be a pain in the ass to mod 
> if i have to rewrite it as the former

$var = &some_routine(); #make sure you use the return function in your subroutine.
if ($var == 1) { #do something or nothing }
else { #do something or nothing}



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

Date: Wed, 21 Jan 2004 11:24:06 -0500
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: problem with 'or' statement
Message-Id: <400EA7A6.4060301@gwu.edu>

lucas wrote:
> is there some way i can write:
> if (some_routine()) { do_this(); and_that(); }
> 
> like so: 
> some_routine() || { do_this(); and_that(); }

Well, no.  They don't do the same thing.  The first does do_this()
and and_that() if some_routine() is true.  The second does the
two functions only if some_routine() *isn't* true.  Perhaps you
wanted this, instead:

some_routine() && { do_this(); and_that(); }

                     Chris Mattern



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

Date: Wed, 21 Jan 2004 10:46:13 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: problem with 'or' statement
Message-Id: <slrnc0tb6l.783.tadmc@magna.augustmail.com>

$_@_.%_ <$_@_.%_> wrote:
>> is there some way i can write:
>> if (some_routine()) { do_this(); and_that(); }
>> 
>> like so: 
>> some_routine() || { do_this(); and_that(); }
>> 
>> the reason is, i have a bunch of code that would be a pain in the ass to mod 
>> if i have to rewrite it as the former
> 
> $var = &some_routine();


Why are you using the ampersand?

   $var = some_routine(); 


>  #make sure you use the return function in your subroutine.


Why do you need to make sure you use the return function in your subroutine?


> if ($var == 1) { #do something or nothing }
> else { #do something or nothing}


Is your followup somehow related to the question that was asked?

I'm not seeing it...


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


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

Date: Wed, 21 Jan 2004 12:17:59 -0500
From: lucas <aolblowz@yahoo.com>
Subject: Re: problem with 'or' statement
Message-Id: <r8idnXT2-MzVKZPdRVn-hQ@golden.net>

Thanks everyone for your posts


Gunner, Chris and Bernard have exactly what I need.  I just never thought of 
using the do {} to exectute the routines.

Tad: || = or

Thanks again ;)
-- 
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------


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

Date: Wed, 21 Jan 2004 17:39:16 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: problem with 'or' statement
Message-Id: <x7znchcibg.fsf@mail.sysarch.com>

>>>>> "l" == lucas  <aolblowz@yahoo.com> writes:

  l> Thanks everyone for your posts
  l> Gunner, Chris and Bernard have exactly what I need.  I just never thought of 
  l> using the do {} to exectute the routines.

  l> Tad: || = or

no it doesn't. you will burn yourself if you think that.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 21 Jan 2004 11:58:45 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: problem with 'or' statement
Message-Id: <slrnc0tfel.7gr.tadmc@magna.augustmail.com>

lucas <aolblowz@yahoo.com> wrote:

> Tad: || = or


No it doesn't.

You should perhaps go find out what is different between them:

   perldoc perlop


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


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

Date: Thu, 22 Jan 2004 22:31:00 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: problem with 'or' statement
Message-Id: <lje0105mvh1sc5t103if89i5o20lgjdk86@4ax.com>

On Wed, 21 Jan 2004 07:34:07 +0100, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:

>lucas wrote:
>> is there some way i can write:
>> if (some_routine()) { do_this(); and_that(); }
>> 
>> like so: 
>> some_routine() || { do_this(); and_that(); }
>
>This is valid code, equivalent to the first example:
>
>     some_routine() and do { do_this(); and_that() };

Also some_routine() and do_this(), and_that();


Michele
-- 
# This prints: Just another Perl hacker,
seek DATA,15,0 and  print   q... <DATA>;
__END__


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

Date: Thu, 22 Jan 2004 23:59:28 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: problem with 'or' statement
Message-Id: <l5l010tdht02q38db80oa38vqsv0gmpvc5@4ax.com>

On Wed, 21 Jan 2004 12:17:59 -0500, lucas <aolblowz@yahoo.com> wrote:

>Tad: || = or

(1) || != or (see perldoc perlop)

  $x = 0 or print 'cool!';
  $y = 0 || print 'cool!';
  print $x,$y;

(2) I bet you whatever you like Tad knows that || is "much like" 'or'.
He means that you didn't have a "problem with 'or' statement".

(3) I decided not to be fussy in my previuous post in this thread, but
your second snippet (notwithstanding the fact that it was incorrect -
as you knew, and this is the reason why you were asking here),
suggested a *working* form (e.g. that with 'do') that was not
equivalent to the first snippet: you should have asked about the 'and'
operator!


Michele
-- 
# This prints: Just another Perl hacker,
seek DATA,15,0 and  print   q... <DATA>;
__END__


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

Date: Thu, 22 Jan 2004 01:14:47 -0500
From: lucas <aolblowz@yahoo.com>
Subject: Re: problem with 'or' statement
Message-Id: <PJednd447-HF95LdRVn-hQ@golden.net>

Michele Dondi wrote:

> On Wed, 21 Jan 2004 12:17:59 -0500, lucas <aolblowz@yahoo.com> wrote:
> 
>>Tad: || = or
> 
> (1) || != or (see perldoc perlop)
> 
>   $x = 0 or print 'cool!';
>   $y = 0 || print 'cool!';
>   print $x,$y;
> 
> (2) I bet you whatever you like Tad knows that || is "much like" 'or'.
> He means that you didn't have a "problem with 'or' statement".
> 
> (3) I decided not to be fussy in my previuous post in this thread, but
> your second snippet (notwithstanding the fact that it was incorrect -
> as you knew, and this is the reason why you were asking here),
> suggested a *working* form (e.g. that with 'do') that was not
> equivalent to the first snippet: you should have asked about the 'and'
> operator!
> 
1:I actually forgot a ! in if (!some_routine()) {}
2:the reason I thought that || = or was because I've seen things like 
open(FILE,"file") || die; and open(FILE,"file") or die;
3:thanks for clearing up the || != or thing for me

-- 
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------


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

Date: Sat, 24 Jan 2004 16:07:52 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: problem with 'or' statement
Message-Id: <3uv4101r8nhhpmkck6l0aa9gbuv1c1qcop@4ax.com>

On Thu, 22 Jan 2004 01:14:47 -0500, lucas <aolblowz@yahoo.com> wrote:

>1:I actually forgot a ! in if (!some_routine()) {}

Well, it's obvious (even) from your .sig that you're mad about the

  something || something else

syntax. No wonder: that's cool! But &&/and's short circuiting
semantics is just as cool and IMHO more straightforward in most
situations (than using a "!", which is convoluted syntax, if not
really necessary, still IMHO).

You'll also notice that && and || and "and", and "or" respectively
have different precedences so that you can write unambiguously
statements like this one:

  # fake example
  -f and /\.txt/ or
    warn "`$_': not a regular file or has an incorrect extension\n"
    for @ARGV;


Michele
-- 
# This prints: Just another Perl hacker,
seek DATA,15,0 and  print   q... <DATA>;
__END__


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

Date: Thu, 29 Jan 2004 11:09:37 +0000 (UTC)
From: Guru03 <Guru03@despammed.com>
Subject: Problem with MIME::Entity
Message-Id: <Xns947F7BD10732BGuru03despammedcom@193.43.96.1>

Hi, I must prepare an email with header, body and an attachment.
The header is on a text file "head.txt".


my $miment = MIME::Entity -> new ();
my $mimhead = MIME::Head->from_file ("head.txt") || die "error";

$miment -> head ($mimhead); # puts the MIME::Head into MIME::Entity

my $mbody = new MIME::Entity->build(Data => "ciao",
                     Type        => "text/plain",
                     Encoding    => "quoted-printable",);

$miment -> add_part ($mbody); # puts the MIME::Body into MIME::Entity

$miment -> attach (Data => "blabla",             # adds the attachment
                   Type => 'application/xml');

$miment -> print;


the result is:

Date: Tue, 21 Oct 2003 13:41:19 +0200 (ora legale Europa occidentale)
From: Guru03
To: Guru04
Subject: test email
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="----------=_1075373658-1352-0"

This is a multi-part message in MIME format...

------------=_1075373658-1352-0

Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.411 (Entity 5.404)

ciao
------------=_1075373658-1352-0
Content-Type: application/xml
Content-Disposition: inline
Content-Transfer-Encoding: base64

YmxhYmxhCmV3cXdlcQp3cWV3cWV3cWU=

------------=_1075373658-1352-0--


The body pard is invalid... that fields above "ciao" (from Content-Type 
to X-Mailer) should NOT be shown.

How can I do? I'm getting to be fool...


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

Date: Thu, 29 Jan 2004 09:01:32 -0500
From: Tim Heaney <theaney@cablespeed.com>
Subject: Re: Problem with MIME::Entity
Message-Id: <87fzdyetvn.fsf@mrbun.watterson>

Guru03 <Guru03@despammed.com> writes:

> Hi, I must prepare an email with header, body and an attachment.
> The header is on a text file "head.txt".

I guess head.txt does not have a

  Content-type: multipart/...

line? Then I think you want bodyhandle instead of add_part

  $miment -> bodyhandle ($mbody);

Then the entity will be promoted to multipart when you do the attach.

Alternatively, add the content-type to the head.txt and then just
attach your body, rather than building a separate entity.

I hope this helps,

Tim


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

Date: Thu, 22 Jan 2004 19:28:01 -0600
From: "Hiro" <yas_okamoto@hotmail.com>
Subject: Re: Problem with table in the module HTML::TextToHtml
Message-Id: <da2e7d8f0c549b8426b67605a48c0086@localhost.talkaboutprogramming.com>

 I had a same problem and my problem was line-end charactor. I was using perl in cygwin on WinXP and the text file line-end charactors were Windows one(/r/n), so TextToHTML couldn't convert the text file into HTML correctly.
 If you are using cygwin or linux you can use command dos2unix to convert the format.

 Or another thing you should check is you are using BORDER type of format in your text file or your should try to turn on ALIGN, PGSQL, DELIM types.





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

Date: Wed, 21 Jan 2004 17:27:58 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: process ids
Message-Id: <210120041727587835%jgibson@mail.arc.nasa.gov>

In article <bu6hj4$rd7$1@news.cis.ohio-state.edu>, Robert Mohr
<mohr.42@osu.edu> wrote:

> Is there a way for a program outside of Perl to be run in the background 
> and have Perl store the process id.  That is, if I want to run the 
> program 'program', I could run something similar to `program &` and get 
> something like '[1] 12834' from it (what I'd get from running 'program 
> &' from the command line).

You can fork() and exec() the external program. The fork() will return
the PID of the child process to the parent process. The external
program will run "in the background", or at least at the same priority
level as your perl process. See "perldoc -f fork" and "perldoc -f
exec". You can also start the external program in the child process
with the backtick or qx// operator, and thus capture the output of the
program. However, in this case the program is running as a grandchild
of the perl program with its own PID.

You can also start an external program with the open() function by
putting a pipe character before or after the executable name. See
"perldoc -f open" and search for 'pipe'. The open returns the PID of
the child process. Where you put the pipe depends upon whether you wish
to send the program input or receive its output.


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

Date: Sun, 25 Jan 2004 01:42:19 +0000 (UTC)
From: Irving Kimura <irving_kimura@lycos.com>
Subject: Programmer's notebook: static variables in Perl
Message-Id: <buv6tr$6fs$1@reader2.panix.com>



I'm a newcomer to Perl, and though I can already write useful
scripts, I'm still at the stage of learning about good Perl idioms.
Here I'm interested in learning more about static-like variables.

When programming C, I like using static variables to hold function-local
constants that will not change value throughout the program's
execution.  E.g.

  int foo( int bar, int baz ) {
     static int frobozz = SOME_CONFIG_MACRO;
     int retval;

     /* do stuff with bar, baz, and frobozz */

     return retval;
  }

Here frobozz is initialized only once, no matter how often foo is
called.

In Perl, one can use block scoping to achieve a similar effect
(almost):

  FOO_BLOCK:
  {
     my $frobozz = SOME_CONFIG_CONSTANT;
  
     sub foo {
       my ($bar, $baz) = @_;
  
       # do stuff with $bar, $baz, and $frobozz;
  
       $retval;
     }
  }

But there's a problem with this version of a static variable.  If
a call to foo() happens lexically before FOO_BLOCK, then $frobozz
is undefined.  This forces a potentially undesired ordering in the
placement of such sub definitions in the file.

The only way around this that I can think of is this:

  FOO_BLOCK:
  {
     my $frobozz;

     sub foo {
       $frobozz ||= SOME_CONFIG_CONSTANT; 
       my ($bar, $baz) = @_;
   
       # do stuff with $bar, $baz, and $frobozz;
   
       $retval;
     }
  }

This means that $frobozz gets evaluated one extra time, tested,
and possibly assigned to (if SOME_CONFIG_CONSTANT happens to evaluate
to false) during every call to foo.

Is there a way to more closely replicate the behavior of C statics
than this?

TIA,

Irv




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

Date: Sun, 25 Jan 2004 02:44:32 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Programmer's notebook: static variables in Perl
Message-Id: <40132D8A.6050001@rochester.rr.com>

Irving Kimura wrote:

 ...
> Here I'm interested in learning more about static-like variables.
> 
> When programming C, I like using static variables to hold function-local
> constants that will not change value throughout the program's
> execution.  E.g.
> 
>   int foo( int bar, int baz ) {
>      static int frobozz = SOME_CONFIG_MACRO;
>      int retval;
> 
>      /* do stuff with bar, baz, and frobozz */
> 
>      return retval;
>   }
> 
> Here frobozz is initialized only once, no matter how often foo is
> called.
> 
> In Perl, one can use block scoping to achieve a similar effect
> (almost):
 ...


Check out the "use constant" pragma.  It might be what you are looking for:

    perldoc constant

> Irv

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Sun, 25 Jan 2004 03:11:47 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Programmer's notebook: static variables in Perl
Message-Id: <401332ec.420988419@news.erols.com>

Irving Kimura <irving_kimura@lycos.com> wrote:

:   FOO_BLOCK:
:   {
:      my $frobozz;
: 
:      sub foo {
:        $frobozz ||= SOME_CONFIG_CONSTANT; 
:        my ($bar, $baz) = @_;
:    
:        # do stuff with $bar, $baz, and $frobozz;
:    
:        $retval;
:      }
:   }
: 
: This means that $frobozz gets evaluated one extra time, tested,
: and possibly assigned to (if SOME_CONFIG_CONSTANT happens to evaluate
: to false) during every call to foo.
: 
: Is there a way to more closely replicate the behavior of C statics
: than this?

Do the initialization in a BEGIN or INIT block.

    {
        my $frobozz;
        INIT{ $frobozz = SOME_CONFIG_CONSTANT; }
        sub foo {
            my ($bar, $baz) = @_;
            # do stuff with $bar, $baz, and $frobozz;
            $retval;
        }
    }

See "Persistent Private Variables" in perlsub.



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

Date: Sat, 24 Jan 2004 21:08:43 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Programmer's notebook: static variables in Perl
Message-Id: <slrnc16cpr.5go.tadmc@magna.augustmail.com>

Bob Walton <invalid-email@rochester.rr.com> wrote:
> Irving Kimura wrote:
> 

>> Here I'm interested in learning more about static-like variables.
>> 
>> When programming C, I like using static variables to hold function-local
>> constants 


> Check out the "use constant" pragma.


But that is package-scoped. 

The OP wanted it block-scoped (to a function's block).


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


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

Date: 26 Jan 2004 18:00:21 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Programmer's notebook: static variables in Perl
Message-Id: <u965ey7fpm.fsf@wcl-l.bham.ac.uk>

tiltonj@erols.com (Jay Tilton) writes:

> Irving Kimura <irving_kimura@lycos.com> wrote:
> 
> :   FOO_BLOCK:
> :   {
> :      my $frobozz;
> : 
> :      sub foo {
> :        $frobozz ||= SOME_CONFIG_CONSTANT; 
> :        my ($bar, $baz) = @_;
> :    
> :        # do stuff with $bar, $baz, and $frobozz;
> :    
> :        $retval;
> :      }
> :   }
> : 
> : This means that $frobozz gets evaluated one extra time, tested,
> : and possibly assigned to (if SOME_CONFIG_CONSTANT happens to evaluate
> : to false) during every call to foo.
> : 
> : Is there a way to more closely replicate the behavior of C statics
> : than this?
> 
> Do the initialization in a BEGIN or INIT block.
> 
>     {
>         my $frobozz;
>         INIT{ $frobozz = SOME_CONFIG_CONSTANT; }
>         sub foo {
>             my ($bar, $baz) = @_;
>             # do stuff with $bar, $baz, and $frobozz;
>             $retval;
>         }
>     }

What is the point of INIT{} there?

I can see why sometimes you'd want BEGIN{} there but I have to try
really hard to contrive a situation when...

         my $frobozz;
         INIT { $frobozz = SOME_CONFIG_CONSTANT; }

 ...is better than...

         my $frobozz = SOME_CONFIG_CONSTANT;

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 27 Jan 2004 09:29:28 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Programmer's notebook: static variables in Perl
Message-Id: <40162f5a.616712049@news.erols.com>

Brian McCauley <nobull@mail.com> wrote:

: I can see why sometimes you'd want BEGIN{} there but I have to try
: really hard to contrive a situation when...
: 
:          my $frobozz;
:          INIT { $frobozz = SOME_CONFIG_CONSTANT; }
: 
: ...is better than...
: 
:          my $frobozz = SOME_CONFIG_CONSTANT;

Yes, if it's in a module, using either BEGIN{} or INIT{} just to give
values to variables is wasted effort.  Worse, using INIT{} in a module
being require()d can be disastrous.

But it's not hard at all to create that situation when the code is in
the main program file.



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

Date: 27 Jan 2004 18:32:09 GMT
From: ctcgag@hotmail.com
Subject: Re: Randomise splitting file into two new files
Message-Id: <20040127133209.738$BG@newsreader.com>

"Bumble" <bumble@what.the.heck> wrote:
> Hey all! Basically I require a program that will take a file full records
> (1 per line) and then output these lines into 2 new files, randomly.
> Anyone know of such a program already in existence?

open F1, ">", pop or die $!;
open F2, ">", pop or die $!;
while (<>) {
  if (rand()<0.5) {
     print F1 $_;
  } else {
     print F2 $_;
  };
};
close F1 or die $!;
close F2 or die $!;

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Tue, 27 Jan 2004 20:30:55 -0000
From: "Bumble" <bumble@what.the.heck>
Subject: Re: Randomise splitting file into two new files
Message-Id: <bv6huq$14a$1@news8.svr.pol.co.uk>

ctcgag@hotmail.com wrote:
>
> open F1, ">", pop or die $!;
> open F2, ">", pop or die $!;
> while (<>) {
>   if (rand()<0.5) {
>      print F1 $_;
>   } else {
>      print F2 $_;
>   };
> };
> close F1 or die $!;
> close F2 or die $!;
>
> Xho

Many thanks! Didn't realise it was so straight forward!! It's working great.

-- 
Bumble
http://bumble.rumble.at
http://www.cossar.co.uk

"I'm flat out, you're so beautiful to look at when you cry. Freeze
don't move, you've been chosen as an extra in the movie adaptation of
the sequel to your life. Shady Lane, everyone wants one, Shady Lane,
everybody needs one" - Pavement




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

Date: Tue, 27 Jan 2004 21:59:59 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Randomise splitting file into two new files
Message-Id: <4016DF59.A760871B@acm.org>

Bumble wrote:
> 
> Hey all! Basically I require a program that will take a file full records (1
> per line) and then output these lines into 2 new files, randomly. Anyone
> know of such a program already in existence?

my @fh;
open $fh[ $_ ], '>', "test44_$_.txt" or die $! for 0, 1;
print { $fh[ rand @fh ] } $_ while <>;



John
-- 
use Perl;
program
fulfillment


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

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


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