[18053] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 213 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 5 09:05:31 2001

Date: Mon, 5 Feb 2001 06:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981381909-v10-i213@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 5 Feb 2001     Volume: 10 Number: 213

Today's topics:
    Re: A Meta-Hack for your enjoyment (Martien Verbruggen)
    Re: A Meta-Hack for your enjoyment (Clinton A. Pierce)
    Re: A Meta-Hack for your enjoyment <bart.lateur@skynet.be>
        Cleaning paths <ross.burton@mail.com>
    Re: Cleaning paths <bcaligari@my-deja.com>
        compile module staticly <hauhau@seed.net.tw>
        Emacs modules for Perl programming (Jari Aalto+mail.perl)
    Re: Help: Script only runs if ' -w' is on line 1 mexicanmeatballs@my-deja.com
    Re: JAPH (Anno Siegel)
    Re: Localtime Question <krahnj@acm.org>
        Perl & ZIP Files <maw@markaw.com>
    Re: Perl & ZIP Files <maw@markaw.com>
    Re: Perl & ZIP Files (Rafael Garcia-Suarez)
    Re: Perl & ZIP Files <bart.lateur@skynet.be>
    Re: Problem opening for writing, going nuts, please hel <domning@t-online.de>
    Re: This is driving me nuts and I need a guru <gaverth@home.com>
    Re: This is driving me nuts and I need a guru (Abigail)
    Re: This is driving me nuts and I need a guru <joe+usenet@sunstarsys.com>
    Re: Trouble with split (LK)
        using hash references to store values from multiple tab mirvine555@my-deja.com
    Re: using hash references to store values from multiple (Anno Siegel)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 5 Feb 2001 22:32:28 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: A Meta-Hack for your enjoyment
Message-Id: <slrn97t3qc.vht.mgjv@martien.heliotrope.home>

On Sun, 04 Feb 2001 16:30:43 GMT,
	Clinton A. Pierce <clintp@geeksalad.org> wrote:

> require 5.6;  # We accept summer whenever it arrives

require 5.6.0;

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | That's funny, that plane's dustin'
Commercial Dynamics Pty. Ltd.   | crops where there ain't no crops.
NSW, Australia                  | 


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

Date: Mon, 05 Feb 2001 12:41:28 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: A Meta-Hack for your enjoyment
Message-Id: <Ybxf6.281842$hD4.68149218@news1.rdc1.mi.home.com>

[Posted and mailed]

In article <slrn97t3qc.vht.mgjv@martien.heliotrope.home>,
	mgjv@tradingpost.com.au (Martien Verbruggen) writes:
> On Sun, 04 Feb 2001 16:30:43 GMT,
> 	Clinton A. Pierce <clintp@geeksalad.org> wrote:
> 
>> require 5.6;  # We accept summer whenever it arrives
> 
> require 5.6.0;

That's what I get for typing it in at the last minute to satisfy 
those who insist on running old Perls.  :)


-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours! 
  clintp@geeksalad.org         for details see http://www.geeksalad.org
"If you rush a Miracle Man, 
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Mon, 05 Feb 2001 13:09:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: A Meta-Hack for your enjoyment
Message-Id: <g99t7t4992vkflstauku082567qmiu5a9n@4ax.com>

Clinton A. Pierce wrote:

>require 5.6;  # We accept summer whenever it arrives

In old style, make that 5.006. In the new style, you've already been
corrected, but I'm not sure that version can even be compiled on older
systems. Heh, it wopuld be funny if it couldn't!

But, anyway. If you require use of 5.6.0, then you can also use values
of a hash as Lvalues, so

	for$a(keys %e){$e{$a}=sprintf"%b",$e{$a};}

can be turned into
	
	for(values %e){$_=sprintf"%b",$_}


This answers the question "Did he really spend his time figuring out how
to puzzle together such a program?", but another question crops up
instead: how did you get to the idea of the encrypting program?

-- 
	Bart.


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

Date: Mon, 05 Feb 2001 12:53:29 GMT
From: Ross Burton <ross.burton@mail.com>
Subject: Cleaning paths
Message-Id: <95m7o6$ktm$1@nnrp1.deja.com>

Hi,

I am trying to clean up a path my code is given in the form of
"/home/users/ross/work/from-cvs/system/../../docs".
File::Spec->canonpath does not handle that case (annoyingly), so how
would I do this in Perl? (5.003)

Thanks for any help,
Ross Burton


Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 05 Feb 2001 13:52:07 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: Cleaning paths
Message-Id: <95mb63$nsi$1@nnrp1.deja.com>

In article <95m7o6$ktm$1@nnrp1.deja.com>,

  Ross Burton <ross.burton@mail.com> wrote:
> I am trying to clean up a path my code is given in the form of
> "/home/users/ross/work/from-cvs/system/../../docs".
> File::Spec->canonpath does not handle that case (annoyingly), so how
> would I do this in Perl? (5.003)

An idea would be to save the current directory, try to change to the
new one, 'read' the current working directory, and changing the
directory back to your original.  However, I do not know how to tell
the current working directory from perl without calling the shell pwd.

   chomp (my $curdir = `pwd`);
   chdir "../../brendon";
   chomp (my $newdir = `pwd`);
   chdir $curdir;
   print "Found as $newdir\n";

Brendon
++++



Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 5 Feb 2001 14:21:05 +0800
From: "hauhau" <hauhau@seed.net.tw>
Subject: compile module staticly
Message-Id: <95lgf5$t2f@netnews.hinet.net>

How to compile modules staticly into perl.exe ( don't need DLL) ?




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

Date: 05 Feb 2001 12:55:50 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_981377589@rtfm.mit.edu>

Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>

Announcement: "What Emacs lisp modules can help with programming Perl"

    Preface

        Emacs is your friend if you have to do anything comcerning software
        development: It offers plug-in modules, written in Emacs lisp
        (elisp) language, that makes all your programmings wishes come
        true. Please introduce yourself to Emacs and your programming era
        will get a new light.

    Where to find Emacs

        XEmacs/Emacs, is available to various platforms:

        o   Unix:
            If you don't have one, bust your sysadm.
            http://www.gnu.org/software/emacs/emacs.html
            http://www.xemacs.org/
            Emacs resources at http://home.eu.org/~jari/emacs-elisp.html

        o   W9x/NT:
            http://www.gnu.org/software/emacs/windows/ntemacs.html

Emacs Perl Modules

    Cperl -- Perl programming mode

        .ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
        .<olson@mcs.anl.gov>           Bob Olson (started 1991)
        .<ilya@math.ohio-state.edu>    Ilya Zakharevich

        Major mode for editing perl files. Forget the default
        `perl-mode' that comes with Emacs, this is much better. Comes
        starndard in newest Emacs.

    TinyPerl -- Perl related utilities

        .http://home.eu.org/~jari/tiny-tools-beta.zip
        .http://home.eu.org/~jari/emacs-tiny-tools.html

        If you ever wonder how to deal with Perl POD pages or how to find
        documentation from all perl manpages, this package is for you.
        Couple of keystrokes and all the documentaion is in your hands.

        o   Instant function help: See documentation of `shift', `pop'...
        o   Show Perl manual pages in *pod* buffer
        o   Load source code into Emacs, like Devel::DProf.pm
        o   Grep through all Perl manpages (.pod)
        o   Follow POD manpage references to next pod page with TinyUrl
        o   Coloured pod pages with `font-lock'
        o   Separate `tiperl-pod-view-mode' for jumping topics and pages
            forward and backward in *pod* buffer.
        o   TinyUrl is used to jump to URLs (other pod pages, man pages etc)
            mentioned in POD pages. (It's a general URL minor mode)

    TinyIgrep -- Perl Code browsing and easy grepping

        [TinyIgrep is included in the tgz mentioned above]

        To grep from all installed Perl modules, define database to
        TinyIgrep. There is example in the tgz (ema-tigr.ini) that shows
        how to set up datatbases for Perl5, Perl4 whatever you have
        installed

        TinyIgrep calls Igrep.el to run the find for you, You can adjust
        recursive grep options, ignored case, add user grep options.

        You can get `igrep.el' module from <kevinr@ihs.com>. Ask for copy.
        Check also ftp://ftp.ihs.com/pub/kevinr/

    TinyCompile -- Browsing grep results in Emacs *compile* buffer

        TinyCompile is minor mode for *compile* buffer from where
        you can collapse unwanted lines, shorten the file URLs

            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT

            -->
            cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
            file1:NNN: MATCHED TEXT
            file1:NNN: MATCHED TEXT

End



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

Date: Mon, 05 Feb 2001 11:44:14 GMT
From: mexicanmeatballs@my-deja.com
Subject: Re: Help: Script only runs if ' -w' is on line 1
Message-Id: <95m3me$htd$1@nnrp1.deja.com>

In article <bYtf6.1819$sS4.54587@ozemail.com.au>,
  "Ron Savage" <ron@savage.net.au> wrote:
> As promised:
> :135!:33/:47u:117s:115r:114/:47b:98i:105n:110/:47p:112e:101r:114l:108
It could be that news has cabbaged this somehow, but 135 is
not a "#", 35 is. Also interesting is that the linefeed
char didn't appear in this either.

You could have continued the thing up to the first
line of the program.
perl -le '$_=<>.<>;map{print "$_:". ord $_}/./sg;' x.pl

--
Jon
perl -e '$|=($_)=(pop);A:$_=~s/.(.)(.*)/\r$2$1/;print;
select pop,pop,pop,.10;goto A' ' iname.com   JonBarker@'


Sent via Deja.com
http://www.deja.com/


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

Date: 5 Feb 2001 11:53:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: JAPH
Message-Id: <95m48g$pcc$1@mamenchi.zrz.TU-Berlin.DE>

Godzilla! <godzilla@stomp.stomp.tokyo> wrote in comp.lang.perl.misc:

[...]

>So tell me, why are you boys investing so much time
>and effort into negative commentary about my unique
>JAPH script and, you don't do this to others, those
>who bend the knee and are accepted?

Excessive gloating over a small accomplishment invites this kind of
commentary.

Anno


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

Date: Mon, 05 Feb 2001 10:57:32 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Localtime Question
Message-Id: <3A7E8824.C781400D@acm.org>

Mike McPherson wrote:
> 
> Just in case anybody asks this is the code I need to find out for.

Hi Mike,

A lot of this code is way too complicated. For example the
CurrentLineTime sub could be replaced with Time::Local and about two or
three lines of code.


> #!/usr/bin/perl -w
#Good start, also:
use strict;

> #flush buffer so that output appears immediately
> $| = 1;
> #-------------------------------------------------------------#
> # Written by Michael R. McPherson
> # an ongoing exercise in learning how
> # to script perl or shoot off my foot
> #-------------------------------------------------------------#
> 
> #-------------------------------------------------------------#
> # There is a bug in this program
> # It only works after Feb 29, 2000
> # This is due to the correction number from
> # &CurrentLineTime for leap year
> # I will fix this
> #-------------------------------------------------------------#
> 
> #-------------------------------------------------------------#
> # Problem::: Figure out how many Days in a month of a given year
> # and what day each falls on. Then figure out how many Mondays
> # Tuesdays ect ...
> #-------------------------------------------------------------#
> #Command line input for determining the month to be processed
> print "Please enter the the year in YYYYMM you would like to process:";
> my $indate = <STDIN>;
> chomp $indate;
> my $cordate = $indate."01000000";
> my $inyear = substr($indate,0,4);
> my $leap = &leap($inyear);
> my @array = localtime(&CurrentLineTime($cordate));
> my $month = $array[4];

When you call subs you should omit the '&', it could cause unexpected
bugs in your program if @_ already has values in it.
perldoc perlsub

> #Define Days in month and there names.
> my %DaysInMonth =
> (0,31,1,$leap,2,31,3,30,4,31,5,30,6,31,7,31,8,30,9,31,10,30,11,31);
> my %NamesOfMonth = (0 => January, 1 => Febuary,
>                     2 => March, 3 => April,
>      4 => May, 5 => June,
>      6 => July, 7 => August,
>      8 => September, 9 => October,
>      10 => November, 11 => December);
> my %NameOfDay = (0 => Sunday, 1 => Monday,
>           2 => Tuedsay, 3 => Wednsday,
>      4 => Thursday, 5 => Friday,
>      6 => Saturday);

These hashes look like arrays so why not just use arrays?
my @DaysInMonth = (31,$leap,31,30,31,30,31,31,30,31,30,31);
my @NamesOfMonth = qw(January February March April May June
            July August September October November December);
my @NameOfDay = qw(Sunday Monday Tuesday Wednesday Thursday
                   Friday Saturday);


> #Return The anme of the month and how many days it has.
> my $Month = $NamesOfMonth{$month};
> my $TotalDaysInMonth = $DaysInMonth{$month};

These now become:
my $Month = $NamesOfMonth[$month];
my $TotalDaysInMonth = $DaysInMonth[$month];


> print "\nThe month of $Month";
> print "\nIn The Year of our LORD $inyear";
> print "\nThere are $TotalDaysInMonth days in this month";
> if ($DaysInMonth{1} eq "28") {
>   print "\nThis is a not a leap year";
> } else {
>   print "\nThis is a leap year";
> }
> print "\n";
> 
> my $table = {0,0,1,0,2,0,3,0,4,0,5,0,6,0};

Here you are creating an anonymous hash and storing the reference to the
hash in $table. This also looks like a job for an array and there is no
need to set the values to zero as perl will do this for you
automatically.
my @table;


> my $today;
> foreach $today(1..$TotalDaysInMonth) {
> print "$today \t";
> if ($today == 1 || $today == 2 || $today == 3 || $today == 4 || $today == 5
> || $today == 6 || $today == 7 || $today == 8 || $today == 9){
>     @day = localtime(&CurrentLineTime($indate."0".$today."000000"));
>  print "@day\t";
> } else {
>     @day = localtime(&CurrentLineTime($indate.$today."000000"));
>  print "@day\t";

@day = localtime( CurrentLineTime( sprintf "$indate%02d000000", $today )
);
Here you are converting the date and time as numbers to the number of
seconds since Jan 1, 1970 and then converting it back to the date and
time in numbers. Why?


> }
> my $wday = $day[6];
> print "$wday\n";
>   if ($wday eq 0) {
>     $table{0}++;
>   }
>   if ($wday eq 1) {
>     $table{1}++;
>   }
>   if ($wday eq 2) {
>     $table{2}++;
>   }
>   if ($wday eq 3) {
>     $table{3}++;
>   }
>   if ($wday eq 4) {
>     $table{4}++;
>   }
>   if ($wday eq 5) {
>     $table{5}++;
>   }
>   if ($wday eq 6) {
>     $table{6}++;
>   }

You don't need all these if statements.
$table[$wday]++;  # this is all you need - assuming table is an array.


> }
> 
> print "\nThere are $table{0} Sundays";
> print "\nThere are $table{1} Mondays";
> print "\nThere are $table{2} Tuesdays";
> print "\nThere are $table{3} Wednsdays";
> print "\nThere are $table{4} Thursdays";
> print "\nThere are $table{5} Fridays";
> print "\nThere are $table{6} Saturdays\n";
> exit;
> #---------------------------------------------------------------------------
> #  usage.pl function - CurrentLineTime
> #    Purpose  : Converts the date & time from a cdr entry into number
> #  of seconds since Jan 1, 1970
> #    Format:YYYYMMDDHHMMSS
> #---------------------------------------------------------------------------
> sub CurrentLineTime {
>     my $time = 0;
>     my $date = $_[0];
> my $day = substr($date,6,2);
> my $month = substr($date,4,2);
> my $year = substr($date,0,4);
> print "$year.$month.$day\t";
>     my %month = ("01", 0,   "02", 31,   "03", 59, "04", 90,
>               "05", 120, "06", 151, "07", 181, "08", 212,
>      "09", 243, "10", 273, "11", 304, "12", 334);
>     $time += (substr($date,0,4) - 1970) * 31536000;
>     $time += ($month{substr($date,4,2)} + substr($date,6,2) - 1) * 86400;
>     my ($hours, $minutes, $seconds);
>  if (substr($date,8,2) eq "  ") {
>      $hours = 0;
>     } elsif (substr($date,8,1) eq " ") {
>         $hours = substr($date,9,1);
>     } else {
>      $hours = substr($date,8,2);
>  }
>  if (substr($date,10,2) eq "00" || substr($date,10,2) eq "  "){
>         $minutes = 0;
>     }elsif (substr($date,10,1) eq "0" || substr($date,10,1) eq " "){
>         $minutes = substr($date,11,1);
>  } else {
>      $minutes = substr($date,10,2);
>  }
>  if (substr($date,12,2) eq "00" || substr($date,12,2) eq "  "){
>      $seconds = 0;
>  }elsif (substr($date,12,1) eq "0" || substr($date,12,1) eq " "){
>         $seconds = substr($date,13,1);
>  } else {
>      $seconds = substr($date,12,2);
>  }
> 
>  $time += ($hours * 3600);
>  $time += ($minutes * 60);
>     $time += $seconds;
> 
>     # Total Correction = (# of leap years) + (System Clock Correction)
>     # There have been 8 leap years since 1970.
>     # System clock correction is -10 hours for this specific system.
>  # Total Correction = 691200 - 10*3600 for this specific system.
> 
>  #Need to make dynamic
>  #on any given day figure how many leap years since 1970
> 
>  $time += 86400 * 8;
>  $time -= 36000 ; #Correction for Time Zone
>     return $time;
> }



use Time::Local;
sub CurrentLineTime {
    my $time = shift or return undef;
    my @tm = reverse unpack 'a4 a2 a2 a2 a2 a2', $time;
    return timelocal( @tm[0 .. 3], $tm[4] - 1, $tm[5] - 1900 );
}



> #Determin if it is a leep year.
> sub leap {
> my $inyear = $_[0];
> my @leapyear = (2008,2004,2000,1996,1992,1988,1984,1980,1976,1972);
> my ($leap, $item);
>   foreach $item(@leapyear){
>     if ($item eq $inyear) {
>      $leap = 29;
>  last;
>  } elsif ($item ne $inyear) {
>      $leap = 28;
>  }
>   }
>   return $leap;
> }


sub isleap {
    return ( $_[0] % 4 ) ? 28 : ( $_[0] % 100 ) ? 29 : ( $_[0] % 400 ) ?
28 : 29;
}


HTH
John


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

Date: Mon, 5 Feb 2001 13:10:09 -0000
From: "Mark A. Williams" <maw@markaw.com>
Subject: Perl & ZIP Files
Message-Id: <3a7ea684_1@nnrp1.news.uk.psi.net>

Hi There,

I am trying to write a small script, which will retrieve an ascii text file
from a remote location and save it to a local file. However, I am getting
rather confused; should I be using LWP, HTTP or something I don;t know
about? Here's a bit more detail:

Each day an ascii text file is made available at a known location, with a
known name, at a known time, but with an unknown size.
I wan to set up a CRON job, which will fire a Perl script to go and get the
file and save it locally.

Can anyone point me in the right direction, or provide me with any advice?

Thanks


Mark




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

Date: Mon, 5 Feb 2001 13:22:21 -0000
From: "Mark A. Williams" <maw@markaw.com>
Subject: Re: Perl & ZIP Files
Message-Id: <3a7ea943_1@nnrp1.news.uk.psi.net>

Sorry about the header previously, should read Perl & remote CSV files

Thanks
"Mark A. Williams" <maw@markaw.com> wrote in message
news:3a7ea684_1@nnrp1.news.uk.psi.net...
> Hi There,
>
> I am trying to write a small script, which will retrieve an ascii text
file
> from a remote location and save it to a local file. However, I am getting
> rather confused; should I be using LWP, HTTP or something I don;t know
> about? Here's a bit more detail:
>
> Each day an ascii text file is made available at a known location, with a
> known name, at a known time, but with an unknown size.
> I wan to set up a CRON job, which will fire a Perl script to go and get
the
> file and save it locally.
>
> Can anyone point me in the right direction, or provide me with any advice?
>
> Thanks
>
>
> Mark
>
>




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

Date: Mon, 05 Feb 2001 13:42:53 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Perl & ZIP Files
Message-Id: <slrn97tbf2.5h3.rgarciasuarez@rafael.kazibao.net>

Mark A. Williams wrote in comp.lang.perl.misc:
> 
> I am trying to write a small script, which will retrieve an ascii text file
> from a remote location and save it to a local file. However, I am getting
> rather confused; should I be using LWP, HTTP or something I don;t know
> about? Here's a bit more detail:
> 
> Each day an ascii text file is made available at a known location, with a
> known name, at a known time, but with an unknown size.
> I wan to set up a CRON job, which will fire a Perl script to go and get the
> file and save it locally.

What kind of 'remote location' is it ? Is the file available via HTTP ?
HTTPS ? FTP ? rsync ? remote login ? another protocol ? There are Perl
modules to handle those protocols but you didn't told us what protocol
you want.

If this is HTTP, there are many options. You can use the LWP::Simple
module, it's very simple, as its name says. You can also avoid using
Perl completely and use a specialized program to retrieve files via
HTTP, such as wget (http://www.gnu.org/software/wget/wget.html).

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Mon, 05 Feb 2001 13:59:10 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl & ZIP Files
Message-Id: <jbct7to8p3q2h35hf0rg7gtauekbrq9oe4@4ax.com>

Mark A. Williams wrote:

>I am trying to write a small script, which will retrieve an ascii text file
>from a remote location and save it to a local file. However, I am getting
>rather confused; should I be using LWP, HTTP or something I don;t know
>about? Here's a bit more detail:

HTTP is the protocol, LWP the suite of libraries.

	use LWP::Simple;
	print getstore 'http://that.domain.net/that/file.txt',
	  '/local/file.txt';

You needn't print out the outcome, but you should retreive "200" (OK).

-- 
	Bart.


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

Date: Mon, 05 Feb 2001 12:35:43 +0100
From: "Ekkehard Domning" <domning@t-online.de>
Subject: Re: Problem opening for writing, going nuts, please help!
Message-Id: <3A7E900F.BF6DE408@192.168.0.5>

Hello,
without the content of $forum_dir and $userfile I can not say what
happened.
It might be possible that You read from a third file without
terminating.
Best regards
Ekkehard

misterfive@my-deja.com wrote:
> =

> Ok, I am going totaly nuts here. I'm modifying some existing BBS code. =
 I am
> trying to open a file for writing, and the program stops after the open=

> statement. (No, it does not execute the "die" statement, it just stop.)=

> =

> I'd suspect a permission problem, except that other parts of the code h=
appily
> create files in the same directory I'm trying to create/write to with t=
his
> code. I've tried creating the file manually, setting write permissions =
for
> everyone. It will read the file just fine, but will not write to it, an=
d
> still stops right after the open for write statement.
> =

> Here's the segment that's giving me a headache: (I've resorted to print=

> statements to pinpoint the problem: the code compiles just fine...)
> =

>     if ($session ne $old_session) {
>     print "Inside session compare<br>";
>     print "$forum_dir/$userfile<br>";
>     open(USERFILE, ">$forum_dir/$userfile") ||
>     &CgiDie("Could't open $userfile for writing");
>         print "File opened for writing";
>         print USERFILE "$high_number\n";
>         print USERFILE "$session\n";
>         close (USERFILE);
>         print "end of write routine...";
>     }
> =

> The end result is:
> ----
> Inside session compare
> CorrectDir/CorrectFile
> ----
> =

> (and that's it. No writing to the file is done if the file is there, th=
e file
> is not created if it isn't.)
> =

> Other code that looks exactly like this write statement creating other =
files
> works fine. If the userfile is there, it reads it fine using       open=

> (USERFILE, "<$forum_dir/$userfile") ||       &CgiDie("Error Opening Use=
rfile
> $userfile\n");
> =

> so it's not something weird with the filename.
> =

> The directory has write permission, and other files have been created i=
n the
> same directory.
> =

> I just don't get it. Am I missing something basic? Something not so bas=
ic?
> Does it just hate me?
> =

> Help!!
> =

> Sent via Deja.com
> http://www.deja.com/

-- =

DomIS Internet Solution - Ekkehard Domning
Spahner Str. 11 - D-49751 S=F6gel
Mail: edo@domis.de Internet: http://www.domis.de


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

Date: Mon, 05 Feb 2001 13:26:22 GMT
From: "Tim Gaverth" <gaverth@home.com>
Subject: Re: This is driving me nuts and I need a guru
Message-Id: <2Sxf6.67348$B6.17690467@news1.rdc1.md.home.com>

Thanks Abigail, but what's the fix? The db queries are processing all
results. Here's a sample of how I'm doing that:
---
my $dbh = $self->{'dbh'}; #this is inherited
my $query = (
    "select fieldone, fieldtwo ",
    "from db1..table1 ",
    "where crit = value ",
    );
$self->dbcmd($dbh,$query) || return undef;
$self->sql_execute($dbh) || return undef; #my sql_execute is inherited and
ends with a dbresults command
my $results = [];
while ( my $row = $dbh->dbnextrow(1) ) {
    push (@$results, $row);
}
return $results;

Any more thoughts?

Abigail <abigail@foad.org> wrote in message
news:slrn97srcg.6au.abigail@tsathoggua.rlyeh.net...
> Bart Lateur (bart.lateur@skynet.be) wrote on MMDCCXV September MCMXCIII
> in <URL:news:ku0s7tccmv86ommtrvh8u7cve81cj43do3@4ax.com>:
>
> Probably not; it looks like Tim is trying to do a query on a
> handle that still has results waiting - they should be either
> fetched, or discharded. This, however, isn't a Perl problem.
>
>
>
> Abigail
> --
> package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
>                                       print } sub __PACKAGE__ { &
>                                       print (     __PACKAGE__)} &
>                                                   __PACKAGE__
>                                             (                )




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

Date: 5 Feb 2001 13:43:01 GMT
From: abigail@foad.org (Abigail)
Subject: Re: This is driving me nuts and I need a guru
Message-Id: <slrn97tbf5.7qj.abigail@tsathoggua.rlyeh.net>

Tim Gaverth (gaverth@home.com) wrote on MMDCCXV September MCMXCIII in
<URL:news:2Sxf6.67348$B6.17690467@news1.rdc1.md.home.com>:
"" Thanks Abigail, but what's the fix? The db queries are processing all
"" results. Here's a sample of how I'm doing that:
"" ---
"" my $dbh = $self->{'dbh'}; #this is inherited
"" my $query = (
""     "select fieldone, fieldtwo ",
""     "from db1..table1 ",
""     "where crit = value ",
""     );

A print $query would help. -w would have told you so.

"" $self->dbcmd($dbh,$query) || return undef;
"" $self->sql_execute($dbh) || return undef; #my sql_execute is inherited and
"" ends with a dbresults command
"" my $results = [];
"" while ( my $row = $dbh->dbnextrow(1) ) {
""     push (@$results, $row);
"" }
"" return $results;
"" 
"" Any more thoughts?


Yes. Don't post Jeopardy style.

*plonk*


Abigail
-- 
perl -wle 'print "Prime" if ("m" x shift) !~ m m^\m?$|^(\m\m+?)\1+$mm'


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

Date: 05 Feb 2001 08:56:10 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: This is driving me nuts and I need a guru
Message-Id: <m3g0htz11h.fsf@mumonkan.sunstarsys.com>

"Tim Gaverth" <gaverth@home.com> writes:

> Thanks Abigail, but what's the fix? The db queries are processing all
> results. Here's a sample of how I'm doing that:
> ---
> my $dbh = $self->{'dbh'}; #this is inherited
> my $query = (
>     "select fieldone, fieldtwo ",
>     "from db1..table1 ",
>     "where crit = value ",
>     );
> $self->dbcmd($dbh,$query) || return undef;
> $self->sql_execute($dbh) || return undef; #my sql_execute is 
> inherited and ends with a dbresults command
> my $results = [];
> while ( my $row = $dbh->dbnextrow(1) ) {
>     push (@$results, $row);
> }
> return $results;

A few questions that might help resolve this:

1) This doesn't look much like DBI; did you write your own subclass
   for it, or is this something from CPAN?

2) Are you certain you have permission to access db1 from $dbh?

3) what does $dbh->dbnextrow return, a list or an anonymous arrayref?
   If it's a list, not a ref, then what happens to your while(){} loop
   when fieldtwo contains a false value (like 0 or undef arising from 
   a NULL entry)?

4) When do you call "finish" on the underlying statement handler?


Joe Schaefer
-- 
"There are two times in a man's life when he should not speculate: when
he can't afford it, and when he can."
                                            --Mark Twain


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

Date: Mon, 05 Feb 2001 13:30:54 GMT
From: lkenny@fisheries.org (LK)
Subject: Re: Trouble with split
Message-Id: <3a7ea93d.1364071@wingate>

On Fri, 02 Feb 2001 20:50:08 GMT, tigra@sky.deep.ru wrote:

>In article <3a7b0abb.21967837@wingate>,
>  lkenny@fisheries.org (LK) wrote:
>> I have written a piece of code that is supposed to split a string on a
>> box.  the code is as follows:
>>
>> 	open(FILE,"$file") || die("Cannot open file $file: $!");
>> 	$data = do { local $/; <FILE>; };
>> 	close (FILE);
>>  	$data =~ s/\n/"|"/eg;
>>   	@data = split(/ /, $data);
>> 	open (FIEL, ">>$dats");
>>  	print FIEL "$data\n\n\n";
>> 	print FIEL "@data";
>>
>> $data has many boxes in it that indicate a record break.  So I want to
>> split on it and make eac record a pipe-delimited file.  When @data
>> prints out, the boxes are gone, but it hasn't split.  It just deleted
>> the boxes.  Is the box character a "special" one, and that is why it
>> isn't working.  Or is there something I'm missing in the split
>> function to make it execute properly.
>>
>> Once again, all help is appreciated.
>
>First of all, why do you use s/\n/"|"/eg instead of just s/\n/|/g ?

Becasue when I take the quotes off I get the following error message:

syntax error at c:\windows\TEMP\DzTemp.pl line 13, near "{ |"syntax
error at c:\windows\TEMP\DzTemp.pl line 20, near "}"
c:\windows\TEMP\DzTemp.pl had compilation errors.

>Next: just can't get what you mean under "boxes". As I've understood a
>"box" is just an ordinary "space". 

The box comes through int he ASCI file, so I don't know if it is
"space" or not.  But I can replace it by using the substitution regex.

>Considering this, your problem is
>both in split and print.
>When you split the substring matching your split pattern actually goes
>nowhere. Only the substrings between matches will populate the target
>list. So this is the place where the "spaces" are deleted.
>So when you ask perl to print "@data" it just does the following:
>print join($", $data);
>So it's common that $" = ''; The result is obvoiuos: you see the output
>as if delimeters were deleted.

I've changed the code a little to help accomodate the weirdness of the
box.  I changed all the boxes into "&"'s, and this works.  But it
still won't splut on the "&".
>
>BTW. Splitting strings with more than one "boxes"  groupped together
>will result in empty records. Then this would help:
>split / +/, $data;
>
>Sergey
>
>
>Sent via Deja.com
>http://www.deja.com/



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

Date: Mon, 05 Feb 2001 12:24:09 GMT
From: mirvine555@my-deja.com
Subject: using hash references to store values from multiple tables
Message-Id: <95m615$jiv$1@nnrp1.deja.com>

Hi,

I'm trying to extract some values from a table, and store them in a hash
to include later in my script. The tables have the form:

Reason  M1E507 M1E508 M1E509 M1E510
InProd  11:45  11:45  9:04   .
WtMtce  0:15   0:15   .      .
InMtce  .      .      2:56   .
No_WIP  .      .      .      12:00

The total report where this table comes from contains several tables, it
is updated every 12 hours, and the tables will always vary in both the
number  of columns, the number of rows, and the names on the columns and
the names on the rows.

So the above table could change where No_WIP is missing, but another
code comes in instead.

Ideally I would like to grab the values, and put them in a hash for each
column head it finds.
A bit like:
%M1E507=("InProd","11:45","WtMtce","11:45"...(and so on));
That way I can simply use
$var=$M1E507{InProd};
and get '11:45'

What I've got so far is:

#!/usr/bin/perl
open (LOG, ">test.log");

my $file="status.txt";
open (FILE,"<  $file") or die "cant open $file $!";
my (@line,$text,$item);
while (<FILE>){
    $text=$_;
    chomp($text);
    @line=split / /,$text;

    # get rid of empty fields due to uneven gaps between words.
    # (only way I could get it to work!)
    foreach $item(@line){
        if ($item){
            push((@words),$item);
        }

    }
    print LOG "words: @words\n";
    my $num_of_cols=@words;

    #when we get here we've left the current table
    if($words[1]=~ m/Click/){

	 $a=0; # stop processing this table

         print LOG "REF: ".$M1E507{InProd}."\n";
         while (($key,$value) = each(%{M1E507})){
             print LOG "KEY: $key\nVALUE: $value\n";
             exit;
         }
    }
    if($words[0]=~ m/Reason/){
       @testers=@words[1..$num_of_cols-1];
	print LOG "testers: @testers\n";

       $a=1;
    }

    elsif($a){
        my @times=@words[2 .. $num_of_cols];
        my $t=0;
        foreach $tester_ (@testers){
            if($testers[$t]=~ m/M1/g){
                print LOG "tester== $tester_\n";
                $reftester=\%tester_;
                ${$reftester}{${$words[1]}}=$times[$t];
                print  LOG "t: $t, time : $times[$t]\n";
                print  LOG "testerref: ".$reftester{${$words[1]}}."\n";
                print  LOG "words[1] :".$words[1]."\n";
                print LOG "values: ".values(%{M1E507})."\n";
                print LOG "KEY now: ".keys(%M1E507)."\n";
                $t++;
            }
        }
    }


    @words="";
}

When I run it, my logfile shows:

words: Reason M1E507 M1E508 M1E509 M1E510
testers: M1E507 M1E508 M1E509 M1E510
words:  InProd 11:45 11:45 9:04 .
tester== M1E507
t: 0, time : 11:45
testerref:
words[1] :InProd
values: 0
KEY now: 0
tester== M1E508
t: 1, time : 11:45
testerref:
words[1] :InProd
values: 0
KEY now: 0
tester== M1E509
t: 2, time : 9:04
testerref:
words[1] :InProd
values: 0
KEY now: 0
tester== M1E510
t: 3, time : .
testerref:
words[1] :InProd
values: 0
KEY now: 0
words:  WtMtce 0:15 0:15 . .
tester== M1E508


 ... and so on.

It seems to grab the column name ok (eg M1E507), grabs the time ok (eg
11:45), and grabs the reason ok (eg InProd). But I'm lost trying to put
this in a hash.
is the line   $reftester=\%tester_; the correct approach?

I'm trying to store it in the hash with:
                ${$reftester}{${$words[1]}}=$times[$t];
I read this (on the first loop) as:
                ${M1E507}{InProd}="11:45";
or at least that's what I'm trying to do.

Can anyone tell me if I'm taking the right approach for this problem.
I'm fairly new to perl, so forgive me if the code looks a little ugly to
 you guys.

I'd appreciate any suggestions,
Regards,
Mark Irivne


Sent via Deja.com
http://www.deja.com/


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

Date: 5 Feb 2001 13:39:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: using hash references to store values from multiple tables
Message-Id: <95maf5$ctt$1@mamenchi.zrz.TU-Berlin.DE>

 <mirvine555@my-deja.com> wrote in comp.lang.perl.misc:
>Hi,
>
>I'm trying to extract some values from a table, and store them in a hash
>to include later in my script. The tables have the form:
>
>Reason  M1E507 M1E508 M1E509 M1E510
>InProd  11:45  11:45  9:04   .
>WtMtce  0:15   0:15   .      .
>InMtce  .      .      2:56   .
>No_WIP  .      .      .      12:00
>
>The total report where this table comes from contains several tables, it
>is updated every 12 hours, and the tables will always vary in both the
>number  of columns, the number of rows, and the names on the columns and
>the names on the rows.
>
>So the above table could change where No_WIP is missing, but another
>code comes in instead.
>
>Ideally I would like to grab the values, and put them in a hash for each
>column head it finds.
>A bit like:
>%M1E507=("InProd","11:45","WtMtce","11:45"...(and so on));

Ugh.  So you want to create a hash whose name you find somewhere
in the data.  This is almost always a bad idea: Variable names belong
in the code and only in the code.

Whenever you are tempted to do this, plan to use what you want to
be a variable name as a hash key.  Then put a reference to the
prospective contents of the variable in the value slot.  This way
you get a name-value association where the names are legitimate
data.

>That way I can simply use
>$var=$M1E507{InProd};
>and get '11:45'

How will you know if you even *have* a variable named %M1E507 in a
particular run?

With a hash as described (named %table, for want of a descriptive
name) you can check if "M1E507" was even mentioned via "exists
$table{ M1E507}".  You can still do

  $var = $table{ M1E507}->{ InProd};

to get the corresponding time (if it is indeed a time).

>What I've got so far is:

[snip 120 lines of code]

I am appending a sketch of how to build %table from your data.

Anno

#!/usr/bin/perl
use strict; use warnings; $| = 1;

my %table;

my @header = split / +/, <DATA>;     # first line is special
shift @header; # get rid of "reason"
chomp @header; # ...and line feed

while ( <DATA> ) {
  chomp;
  my( $reason, @times) = split / +/;
  for ( my $i = 0; $i < @header; $i++ ) {
    my $time = $times[ $i];
    if ( defined $time and $time ne '.' ) {
      $table{ $header[ $i]}->{ $reason} = $time;
    }
  }
}

my $var = $table{ M1E510}->{ No_WIP} if exists $table{ M1E510};
print "var: $var\n"; # $var can still be undefined

__DATA__
Reason  M1E507 M1E508 M1E509 M1E510
InProd  11:45  11:45  9:04   .
WtMtce  0:15   0:15   .      .
InMtce  .      .      2:56   .
No_WIP  .      .      .      12:00



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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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