[31593] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2852 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 4 18:09:25 2010

Date: Thu, 4 Mar 2010 15:09:08 -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, 4 Mar 2010     Volume: 11 Number: 2852

Today's topics:
    Re: Detecting Bourne (or csh) shell from Perl <nospam-abuse@ilyaz.org>
    Re: Detecting Bourne (or csh) shell from Perl <ben@morrow.me.uk>
        How can I write "print $F[4] if exists $F[4]" even simp jidanni@jidanni.org
    Re: How can I write "print $F[4] if exists $F[4]" even  <tadmc@seesig.invalid>
    Re: how to speed up a string-substitution loop? <ben@morrow.me.uk>
        Is there a "poor man's" perldoc? <jl_post@hotmail.com>
    Re: Is there a "poor man's" perldoc? <john@castleamber.com>
    Re: Is there a "poor man's" perldoc? <jl_post@hotmail.com>
    Re: Is there a "poor man's" perldoc? <ben@morrow.me.uk>
    Re: perl -014pe <jimsgibson@gmail.com>
    Re: perl -014pe <nickli2000@gmail.com>
    Re: Prevent script from adding an extra line at the end <tadmc@seesig.invalid>
    Re: Prevent script from adding an extra line at the end <tadmc@seesig.invalid>
        Process between paragraphs in perl <nickli2000@gmail.com>
    Re: Process between paragraphs in perl <tadmc@seesig.invalid>
    Re: tape rotations and tape autoloaders <rocky.allen.ats@gmail.com>
    Re: tape rotations and tape autoloaders <rocky.allen.ats@gmail.com>
    Re: tape rotations and tape autoloaders <tzz@lifelogs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 4 Mar 2010 20:44:11 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Detecting Bourne (or csh) shell from Perl
Message-Id: <slrnhp06sr.i4d.nospam-abuse@powdermilk.math.berkeley.edu>

On 2010-03-04, Ben Morrow <ben@morrow.me.uk> wrote:
>> Reiterating again: is there a way to distinguish (e.g., a Windows)
>> port which uses "native" shell vs Korn-syntax shell.

> Sorry, I thought your question was 'which platforms use DOSish shells'
> not 'are there any Win32 ports which don't'. There is presently only one
> Win32 port, the one in the core, and that uses $ENV{PERL5SHELL} to
> decide which shell to use, falling back to command.com/cmd.exe if it's
> empty.

I know many Windows ports: AS, Strawberry (several flavors, judging by
bug reports for my modules), cygwin...  I expect cygwin uses Bourne...

>> > that's an OS matter, and outside the remit of the perl docs.
>> 
>> This, of course, has nothing to do with OS.  Just what the creator of
>> a particular port decided to use as a shell.
>
> Meh. IMHO a perl which doesn't use the same shell as used by system(3)
> in the standard C library is somewhat broken. 

I would guess that your understanding of non-Unix architechture is
kinda blurred.  There are probably tens of different C libraries, none
of them "standard"...

>>> (And, repeating myself:
>> IMO, if people would listen to me a decade ago, one would not have
>> this mess at all - all shells would use Bourne syntax...) 

> So you would have Win32 perl ship with a sh.exe,

Yes.

> and use that for system and exec?

Yes (by default).  Using (e.g.) Win32::system would switch to using
%COMSPEC%.

> I suspect that would have made Win32 people coming to perl
> rather unhappy.

How would having more scripts working "out of the box" make them unhappy?

>> And having docs mentioning how to write portable code would be nice,
>> would not it?

> The docs repeatedly suggest avoiding the shell wherever possible, and
> doing things in Perl instead.

Definitely, this does not cover the situations when using the shell is
the answer...

Yours,
Ilya


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

Date: Thu, 4 Mar 2010 22:37:32 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Detecting Bourne (or csh) shell from Perl
Message-Id: <cap567-v2f.ln1@osiris.mauzo.dyndns.org>


Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> On 2010-03-04, Ben Morrow <ben@morrow.me.uk> wrote:
> >> Reiterating again: is there a way to distinguish (e.g., a Windows)
> >> port which uses "native" shell vs Korn-syntax shell.
> 
> > Sorry, I thought your question was 'which platforms use DOSish shells'
> > not 'are there any Win32 ports which don't'. There is presently only one
> > Win32 port, the one in the core, and that uses $ENV{PERL5SHELL} to
> > decide which shell to use, falling back to command.com/cmd.exe if it's
> > empty.
> 
> I know many Windows ports: AS, Strawberry (several flavors, judging by
> bug reports for my modules), cygwin...  I expect cygwin uses Bourne...

AS and Strawberry (all the various flavours) apply no more than minor
patches to the core. (This wasn't true once, as I'm sure you remember,
but ActiveState haven't had their own port for a long time.) Cygwin (and
Interix and UWin) don't set $^O = "Win32"; as far as Perl is concerned,
they're mostly a different OS from Win32.

> >> > that's an OS matter, and outside the remit of the perl docs.
> >> 
> >> This, of course, has nothing to do with OS.  Just what the creator of
> >> a particular port decided to use as a shell.
> >
> > Meh. IMHO a perl which doesn't use the same shell as used by system(3)
> > in the standard C library is somewhat broken. 
> 
> I would guess that your understanding of non-Unix architechture is
> kinda blurred.  There are probably tens of different C libraries, none
> of them "standard"...

I'm aware of that. However, TTBOMK there aren't any C libraries for
Win32 which don't use command.com/cmd.exe for system(3).

> >>> (And, repeating myself:
> >> IMO, if people would listen to me a decade ago, one would not have
> >> this mess at all - all shells would use Bourne syntax...) 
> 
> > So you would have Win32 perl ship with a sh.exe,
> 
> Yes.
> 
> > and use that for system and exec?
> 
> Yes (by default).  Using (e.g.) Win32::system would switch to using
> %COMSPEC%.
> 
> > I suspect that would have made Win32 people coming to perl
> > rather unhappy.
> 
> How would having more scripts working "out of the box" make them unhappy?

You would at least need to ship with a reasonable set of utilities, as
well, which would turn perl-for-Win32 into something more like MinGW. I
don't think that's what the people porting perl to Win32 wanted.

> >> And having docs mentioning how to write portable code would be nice,
> >> would not it?
> 
> > The docs repeatedly suggest avoiding the shell wherever possible, and
> > doing things in Perl instead.
> 
> Definitely, this does not cover the situations when using the shell is
> the answer...

No, and I agree it's extremely hard to make such things portable. 

Ben



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

Date: Fri, 05 Mar 2010 03:46:00 +0800
From: jidanni@jidanni.org
Subject: How can I write "print $F[4] if exists $F[4]" even simpler?
Message-Id: <hmp2nd$u50$1@news.datemas.de>

How can I write
  print $F[4] if exists $F[4];
even simpler?
  print if exists for $F[4];
  print if exists $_ for $F[4];
don't work.


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

Date: Thu, 04 Mar 2010 15:00:04 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: How can I write "print $F[4] if exists $F[4]" even simpler?
Message-Id: <slrnhp07jf.k17.tadmc@tadbox.sbcglobal.net>

jidanni@jidanni.org <jidanni@jidanni.org> wrote:

> How can I write
>   print $F[4] if exists $F[4];
> even simpler?


Why do you want to write
  print $F[4] if exists $F[4];
even simpler?


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Thu, 4 Mar 2010 19:05:58 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: how to speed up a string-substitution loop?
Message-Id: <mtc567-kra.ln1@osiris.mauzo.dyndns.org>


Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
> 
> [1] All the profilers for perl I know hook into the debugger, so they
>     execute extra code for each line/block/sub that is executed. Using
>     a SIGPROF handler (like the traditional Unix profiler does) should 
>     have much less overhead - does anyone know a perl profiler which
>     does this?

I don't, but as of 5.10 there is some support for dtrace, if you're on a
system that supports that. (I've never used it, so don't ask me how it
works.)

Ben



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

Date: Thu, 4 Mar 2010 11:19:28 -0800 (PST)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Is there a "poor man's" perldoc?
Message-Id: <a444a88c-64f7-4d9d-92fb-cc6147f86136@a16g2000pre.googlegroups.com>

Hi,

   I use the perldocs frequently when I'm programming in Perl.
However, on some systems I've used, "perldoc" is apparently not
installed (despite the fact that Perl is).  What I'd like is a way to
cleanly extract the perldoc documentation from a module that is
installed on that system.  (For example, I'd like to view the
documentation that I'd normally see with "perldoc Time::Local" on a
system that unfortunately doesn't have "perldoc" installed.)

   I know that I can go to cpan.org and look up the documentation, but
sometimes I'm working on a system cut off from the internet.  Just
extracting the perl documentation from an already installed module
doesn't seem to me to be a very complex issue (although maybe I'm
wrong).

   So what I'm asking is:  Is there a pure-Perl way to view a module's
perldoc documentation, particularly if the "perldoc" package is not
installed (and I have no power to install it)?

   Thanks.

   -- Jean-Luc


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

Date: Thu, 04 Mar 2010 13:44:42 -0600
From: John Bokma <john@castleamber.com>
Subject: Re: Is there a "poor man's" perldoc?
Message-Id: <87635blvmd.fsf@castleamber.com>

"jl_post@hotmail.com" <jl_post@hotmail.com> writes:

>    So what I'm asking is:  Is there a pure-Perl way to view a module's
> perldoc documentation, particularly if the "perldoc" package is not
> installed (and I have no power to install it)?

perldoc *is* pure Perl.

Install Pod::Perldoc and locally [1], it comes with perldoc.
Just set a path to it, or:

perl -MPod::Perldoc -e'Pod::Perldoc->run()' Time::Local

perldoc -q 'own module'

-- 
John Bokma                                                               j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development


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

Date: Thu, 4 Mar 2010 12:09:25 -0800 (PST)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Is there a "poor man's" perldoc?
Message-Id: <d9bbdc42-9d7e-4e31-9bcd-21416a3de0fc@s36g2000prf.googlegroups.com>

> "jl_p...@hotmail.com" <jl_p...@hotmail.com> asked:
> > =A0 =A0So what I'm asking is: =A0Is there a pure-Perl way to view
> > a module's perldoc documentation, particularly if the
> > "perldoc" package is not installed (and I have no power to
> > install it)?
>
> perldoc *is* pure Perl.


On Mar 4, 12:44=A0pm, John Bokma <j...@castleamber.com> replied:
>
> Install Pod::Perldoc and locally [1], it comes with perldoc.
> Just set a path to it, or:
>
> perl -MPod::Perldoc -e'Pod::Perldoc->run()' Time::Local


   Excellent!  I just tried that one command on one system that
doesn't have "perldoc" installed, and the perldoc documentation for
Time::Local appeared!  (So ironically Pod::Perldoc is apparently
already installed, even though the "perldoc" package is not.)

   It even works for regular perldoc pages, like "perlpacktut", like
this:

   perl -MPod::Perldoc -e "Pod::Perldoc->run()" perlpacktut

   If I want to look up a core function, like split(), I can't figure
out how to emulate "perldoc -f split", but I CAN do:

   perl -MPod::Perldoc -e "Pod::Perldoc->run()" perlfunc

and look it up from there.  However, I still can't figure out how to
do things like "perldoc -q 'own module'".  (I'd read through the
"perldoc Pod::Perldoc" documentation, but apparently there isn't
any...)

   Anyway, John, your solution goes above and beyond what I was hoping
for.  (Now I just need to commit it to memory for those times when I
can't look it up.)

   Thanks again!

   -- Jean-Luc


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

Date: Thu, 4 Mar 2010 22:27:41 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Is there a "poor man's" perldoc?
Message-Id: <tno567-v2f.ln1@osiris.mauzo.dyndns.org>


Quoth "jl_post@hotmail.com" <jl_post@hotmail.com>:
> > "jl_p...@hotmail.com" <jl_p...@hotmail.com> asked:
> > >    So what I'm asking is:  Is there a pure-Perl way to view
> > > a module's perldoc documentation, particularly if the
> > > "perldoc" package is not installed (and I have no power to
> > > install it)?
> >
> > perldoc *is* pure Perl.
> 
> 
> On Mar 4, 12:44 pm, John Bokma <j...@castleamber.com> replied:
> >
> > Install Pod::Perldoc and locally [1], it comes with perldoc.
> > Just set a path to it, or:
> >
> > perl -MPod::Perldoc -e'Pod::Perldoc->run()' Time::Local
> 
> 
>    Excellent!  I just tried that one command on one system that
> doesn't have "perldoc" installed, and the perldoc documentation for
> Time::Local appeared!  (So ironically Pod::Perldoc is apparently
> already installed, even though the "perldoc" package is not.)

perldoc almost certainly *is* installed somewhere, it's just not in your
PATH. Check to see if your /usr/bin/perl is a symlink somewhere, and if
the real binary has a 'perldoc' next to it.

OTOH, the 'perldoc' script looks like:

| #!/usr/bin/perl
|     eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
| 	if 0;
| 
| # This "perldoc" file was generated by "perldoc.PL"
| 
| require 5;
| BEGIN { $^W = 1 if $ENV{'PERLDOCDEBUG'} }
| use Pod::Perldoc;
| exit( Pod::Perldoc->run() );

so you could just put that in a file called 'perldoc' somewhere in your
PATH (fix the #! line first, obviously).

>    It even works for regular perldoc pages, like "perlpacktut", like
> 
>    perl -MPod::Perldoc -e "Pod::Perldoc->run()" perlpacktut
> 
>    If I want to look up a core function, like split(), I can't figure
> out how to emulate "perldoc -f split", but I CAN do:
> 
>    perl -MPod::Perldoc -e "Pod::Perldoc->run()" perlfunc
> 
> and look it up from there.  However, I still can't figure out how to
> do things like "perldoc -q 'own module'".  (I'd read through the
> "perldoc Pod::Perldoc" documentation, but apparently there isn't
> any...)

You need an extra '--', to separate the args for perl and the args for
Perl. This is documented in perlrun.

    perl -MPod::Perldoc -e'Pod::Perldoc->run' -- -f split

Ben



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

Date: Thu, 04 Mar 2010 11:40:50 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: perl -014pe
Message-Id: <040320101140501685%jimsgibson@gmail.com>

In article
<9919d605-26f7-4aac-9e01-8d7cd33362f0@i25g2000yqm.googlegroups.com>,
Ninja Li <nickli2000@gmail.com> wrote:

> Hi,
> 
>   I saw the following code about splitting a file into several pieces:
> 
>    perl -014pe 'open(STDOUT,">fred.$.")' fred
> 
>   I couldn't find what -014 means. Please advise.

See 'perldoc perlrun':

"Switches include:

-0[octal/hexadecimal]
     specifies the input record separator ($/) as an octal or
     hexadecimal number. "

-- 
Jim Gibson


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

Date: Thu, 4 Mar 2010 11:54:14 -0800 (PST)
From: Ninja Li <nickli2000@gmail.com>
Subject: Re: perl -014pe
Message-Id: <b0f4f615-cc81-453c-a4a5-b31822c864b2@33g2000yqj.googlegroups.com>

Thanks all for your help.



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

Date: Thu, 04 Mar 2010 14:52:54 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Prevent script from adding an extra line at the end of file
Message-Id: <slrnhp0762.k17.tadmc@tadbox.sbcglobal.net>

Don Pich <dpich@polartel.com> wrote:

> Desired output:
>
> convert the IP into a quad hex form.


    print "convert the IP into a quad hex form.\n";


Done!


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Thu, 04 Mar 2010 14:54:31 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Prevent script from adding an extra line at the end of file
Message-Id: <slrnhp0792.k17.tadmc@tadbox.sbcglobal.net>

Don Pich <dpich@polartel.com> wrote:
> Hey Jue,
>
> The reason I have to do that 


Do what?

Please learn how to make a proper post and followup if you plan
to post or followup in a Usenet newsgroup.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Thu, 4 Mar 2010 11:52:07 -0800 (PST)
From: Ninja Li <nickli2000@gmail.com>
Subject: Process between paragraphs in perl
Message-Id: <c864ad3b-d913-4781-acc8-55c2db166ad5@g11g2000yqe.googlegroups.com>

Hi,

   I have a file with the following format, with common words "Sort
Alphabetically" for each paragraph:

   London|Sort Alphabetically
   line1
   line2
   line3
   Chicago|Sort Alphabetically
   line1
   line2
   Shanghai|Sort Alphabetically
   line1
   line2

   I would like to print the country name after each line under city,
so the output will be something like:
   London|Sort Alphabetically
   line1 | UK
   line2 | UK
   line3 | UK
   Chicago|Sort Alphabetically
   line1 | US
   line2 | US
   Shanghai|Sort Alphabetically
   line1 | China
   line2 | China

   I tried to split each paragraph into separate file base on "Sort
Alphabetically" and then merge them again. This is quite tideous. Is
there an easier way to do this without splitting into separate files?
The following is some of my code:

open(INFILE, "<$file");

foreach $line (<INFILE>)
{
  if ($line =~ /Alphabetically/)
  {
    my @fields = split(/\|/, $line);
    $location = $fields[0];

    if ($location =~ /London/)
    {
      $location = 'UK';
    }
    elsif ($location =~ /Chicago/)
    {
      $location = 'US';
    }
    elsif ($location =~ /Shanghai/)
    {
      $location = 'China';
    }
    elsif ($location =~ /.../)
    {
      $location = '..';
    }

    close(OUTFILE);
    open(OUTFILE, ">$output$location");
  }
    print OUTFILE $line;
}


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

Date: Thu, 04 Mar 2010 15:08:50 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Process between paragraphs in perl
Message-Id: <slrnhp083t.k17.tadmc@tadbox.sbcglobal.net>

Ninja Li <nickli2000@gmail.com> wrote:
> Hi,
>
>    I have a file with the following format, with common words "Sort
> Alphabetically" for each paragraph:
>
>    London|Sort Alphabetically
>    line1
>    line2
>    line3
>    Chicago|Sort Alphabetically
>    line1
>    line2
>    Shanghai|Sort Alphabetically
>    line1
>    line2
>
>    I would like to print the country name after each line under city,
> so the output will be something like:
>    London|Sort Alphabetically
>    line1 | UK
>    line2 | UK
>    line3 | UK
>    Chicago|Sort Alphabetically
>    line1 | US
>    line2 | US
>    Shanghai|Sort Alphabetically
>    line1 | China
>    line2 | China


-----------------
#!/usr/bin/perl
use warnings;
use strict;

my %country = (
    London   => 'UK',
    Chicago  => 'US',
    Shanghai => 'China',
);

my $city;
while ( <DATA> ) {
    if ( /^\s*([^|]+)\|Sort Alphabetically/ ) {
        $city = $1;
        print;
    }
    else {
        chomp;
        print "$_ | $country{$city}\n";
    }
}

__DATA__
   London|Sort Alphabetically
   line1
   line2
   line3
   Chicago|Sort Alphabetically
   line1
   line2
   Shanghai|Sort Alphabetically
   line1
   line2
-----------------


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Thu, 4 Mar 2010 11:27:20 -0800 (PST)
From: "Nix!" <rocky.allen.ats@gmail.com>
Subject: Re: tape rotations and tape autoloaders
Message-Id: <dcf150d6-1cc0-4cee-96ba-8b452a3777db@19g2000yqu.googlegroups.com>

On Mar 4, 1:47=A0pm, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> On 2010-03-04 16:19, Nix! <rocky.allen....@gmail.com> wrote:
>
>
>
> > On Mar 4, 9:39=A0am, "Nix!" <rocky.allen....@gmail.com> wrote:
> >> I have a tape autoloader with 8 tapes. =A0The tapes are labeled monday=
,
> >> tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
>
> >> My backup script needs to be modified to load the correct tape each
> >> friday. =A0A copy of the existing script can be found here:http://bobo=
theclown.org/scripts/compperl
> [...]
> >> I am presently planning to incriment the week number in a txt file
> >> until it reaches 4 and then start over. =A0This seems fail to me. =A0T=
he
> >> text file may be deleted, and the rotation will be lost. =A0It is also=
 a
> >> lot of code to write.
>
> >> Can anyone suggest a more intelligent alternative for finding the 1st,
> >> 2nd, 3rd, and 4th friday relative to the first time the script ever
> >> ran?
>
> > heres what I did:
>
> > #!/usr/bin/perl
>
> > use strict;
>
> use warnings;
>
> > my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =3D
> > localtime(time);
> > my $tapenumber =3D --$wday;
> > my $filename =3D "/backup/scripts/week_of_month";
>
> > if ($wday =3D=3D 5) {
>
> > =A0 =A0 =A0 =A0 open FH15,'<', $filename or die "Could not open $filena=
me: $!
> > \n";
>
> Use lexical filehandles:
>
> =A0 =A0 open my $fh15, '<', $filename or die "Could not open $filename: $=
!";
>
> (and find a better name than "$fh15", e.g. $week_fh)
>
> > =A0 =A0 =A0 =A0 my @weeknumber =3D <FH15>;
> > =A0 =A0 =A0 =A0 my $weekscalar =3D $weeknumber[0];
>
> These two lines can be replaced with
>
> =A0 =A0 =A0 =A0 my $weekscalar =3D <FH15>;
>
> but you should also add a
>
> =A0 =A0 =A0 =A0 chomp($weekscalar);
>
> to remove the trailing newline (and avoid a warning).
>
> > =A0 =A0 =A0 =A0 close FH15;
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ($weekscalar =3D=3D 1) =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $tapenumber =3D 5;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $weekscalar++;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } elsif ($weekscalar =3D=3D 2) =A0 =A0 =
=A0{
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $tapenumber =3D 6;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $weekscalar++;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } elsif ($weekscalar =3D=3D 3) =A0 =A0 =
=A0{
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $tapenumber =3D 7;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $weekscalar++;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } elsif ($weekscalar =3D=3D 4) =A0 =A0 =
=A0{
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $tapenumber =3D 8;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $weekscalar =3D 1;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>
> This whole if/elsif block can be replaced with:
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $tapenumber =3D $weekscalar + 4;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $weekscalar =3D $weekscalar % 4 + 1;
>
> > =A0 =A0 =A0 =A0 open FH15,'>', $filename or die "Could not open $filena=
me: $!
> > \n";
> > =A0 =A0 =A0 =A0 print FH15 $weekscalar;
> > =A0 =A0 =A0 =A0 close FH15;
> > }
>
> > my $loadtape =3D "mtx -f /dev/sg17 load $tapenumber";
> > print "$loadtape\n";
> > my $unloadtape =3D "mtx -f /dev/sg17 unload $tapenumber";
> > print "$unloadtape\n";
>
> > Its ugly but it works, and I can work on something else now. =A0:)
>
>

I knew there was a better way.  This is sexy.  For some reason I
thought if I read a filehandle into a scalar I would only get the
number of elements.  I was prolly smoking crack that day.  Thanks a
lot!


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

Date: Thu, 4 Mar 2010 11:29:39 -0800 (PST)
From: "Nix!" <rocky.allen.ats@gmail.com>
Subject: Re: tape rotations and tape autoloaders
Message-Id: <07babfe7-087a-4b7c-b193-413bf8ee85e5@z35g2000yqd.googlegroups.com>

On Mar 4, 1:55=A0pm, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> On 2010-03-04 16:50, Don Piven <spamt...@piven.net> wrote:
>
> > Nix! wrote:
> >> Hi everyone,
>
> >> I have a tape autoloader with 8 tapes. =A0The tapes are labeled monday=
,
> >> tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
> >> [...]
> >> I am presently planning to incriment the week number in a txt file
> >> until it reaches 4 and then start over. =A0This seems fail to me. =A0T=
he
> >> text file may be deleted, and the rotation will be lost. =A0It is also=
 a
> >> lot of code to write.
> [...]
> > I suppose that if you wanted to be independent and not depend on
> > anything in or on the filesystem that could be modified, you could take
> > the number of days since the epoch, divide by 7 to get number of weeks
> > since the epoch, and use that modulo 4 for your arbitrary week number.
>
> Alternatively you could use the number of the week in the current year:
>
> $tapenumber =3D strftime("%V", localtime) % 4;
>
> However, every few years the first backup of the year will overwrite the
> last backup of the previous year (when the last week is week 53, not
> week 52), so your method is probably preferable.
>
> =A0 =A0 =A0 =A0 hp
Thanks hp.


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

Date: Thu, 04 Mar 2010 15:02:11 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: tape rotations and tape autoloaders
Message-Id: <87mxynkdgs.fsf@lifelogs.com>

On Thu, 4 Mar 2010 10:45:27 -0800 (PST) "Nix!" <rocky.allen.ats@gmail.com> wrote: 

N> I use the grandfather son strategy modified for 5 days a week instead
N> of 7.  That is why I didnt want to use dates as a key.  Over the four
N> friday rotation, at the end of 365 days I will have used 20 tapes + 1
N> annual (remembering that I never overwrite a friday 4)  It doesnt
N> really matter when I begin as it is based on 365 days.

N> By doing it this way I will be able to recover from any day this week,
N> any week this month, any month this year, or any year since the sytem
N> has been in operation.

Sorry to get off-topic, but most backup strategies use incrementals or
differentials in addition to full backups.  If your goal is to do full
recovery, consider daily differentials from Friday and a full backup
every Friday.  That gives you redundancy (Monday's changes will also be
on Tuesday's tape) without using so many tapes.  The nice thing about
full backup solutions is that you'd label your tapes, throw them in a
jukebox, and just assign them to a pool.  Then the software will look in
the pool and figure out if it has a tape that's blank, can be recycled,
etc.

You could also consider something like this:

http://www.blackpepper.co.uk/black-pepper-blog/Using-Amazon-EC2-EBS-S3-for-automated-backups.html

Ted


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 2852
***************************************


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