[25236] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7481 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 3 18:05:45 2004

Date: Fri, 3 Dec 2004 15:05:10 -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           Fri, 3 Dec 2004     Volume: 10 Number: 7481

Today's topics:
    Re: (Newbie Question) Digest::MD5 CPAN module compilati <usenet@morrow.me.uk>
        [OT] Re: vbscript or perl <usenet@morrow.me.uk>
    Re: A problem with fork() and managing processes <bik.mido@tiscalinet.it>
    Re: A problem with fork() and managing processes <bik.mido@tiscalinet.it>
    Re: Complex Search and Replace <jgibson@mail.arc.nasa.gov>
        conditioning system shell output from within Perl - Noo jason@cyberpine.com
    Re: conditioning system shell output from within Perl - <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: conditioning system shell output from within Perl - <tadmc@augustmail.com>
    Re: conditioning system shell output from within Perl - <spamtrap@dot-app.org>
        FAQ 5.25: How do I print to more than one file at once? <comdog@panix.com>
        Monitor a dos console perl program running (Maverick Ieong)
        Obtaining length of binary string <ravi@none.nowhere.com>
    Re: Perl Books (Binny V A)
    Re: Perl classes NOT in separate files <andy.glew@intel.com>
    Re: Pipe input from a Text-File (J. Romano)
    Re: Pipe input from a Text-File <usenet@morrow.me.uk>
        print FILE truncating input <cNaOlSePbA@MvPeLtEsAtSaEr.com>
    Re: print FILE truncating input <cNaOlSePbA@MvPeLtEsAtSaEr.com>
    Re: print FILE truncating input <jkeen_via_google@yahoo.com>
    Re: print FILE truncating input <cNaOlSePbA@MvPeLtEsAtSaEr.com>
        Question on loops and return values (delfuego)
    Re: SQLite - problem connecting to database (or doing a <do-not-use@invalid.net>
    Re: SQLite - problem connecting to database (or doing a <nospam@nospam.com>
    Re: testing for existence of an inline file with Inline (Sven Wolf)
    Re: testing for existence of an inline file with Inline <usenet@morrow.me.uk>
    Re: testing for existence of an inline file with Inline <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 3 Dec 2004 19:38:09 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: (Newbie Question) Digest::MD5 CPAN module compilation errors
Message-Id: <1ur682-b44.ln1@osiris.mauzo.dyndns.org>


Quoth freedive999@hotmail.com (FreeDiver):
> Hi,
>     I am a newbie in Perl.  I am having trouble installing my
> Digest::MD5 CPAN
> module.  We are running Solaris 8 with gcc 3.0.3 (from SMCgcc3 pkg). 
> I've got
> the following error messages when trying to do a "make".  Looks like
> it's complaining about that '-KPIC' option is not recognized.
>      Any idea how I can resolve this problem ??  Do I need another
> compiler
> for this CPAN module installation ??  Is there any other free compiler
> out there ??
> 
> Thanks in advance for your help.
> 
> atlantis# perl Makefile.PL CC=/usr/local/bin/gcc

You must build modules with the same compiler perl was built with, in
this case one of Sun's ccs by the looks of it. 
perl -V:cc -V:ccversion -V:gccversion should enable you to work it out.
Either get hold of a copy of that compiler, or rebuild perl from source
with the compiler you have.

Ben

-- 
   Although few may originate a policy, we are all able to judge it.
                                             - Pericles of Athens, c.430 B.C.
  ben@morrow.me.uk


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

Date: Fri, 3 Dec 2004 19:31:41 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: [OT] Re: vbscript or perl
Message-Id: <thr682-b44.ln1@osiris.mauzo.dyndns.org>


Quoth "Jürgen Exner" <jurgenex@hotmail.com>:
> David wrote:
> > I have to port a moderately complicated unix shell script written for
> > Solaris to Windows.  I've never done Windows scripting before.
> > Should I
> >
> > (a) learn VBScript and implement it in that;
> > (b) install Active Perl on the target Windows box and rewrite the
> > script in perl (which I am familiar with).
> 
> You are kind of comparing model cars and real airplanes. To me that doesn't 
> make much sense.
> 
> I hope you are aware that VB Script is a client-side scripting language 
> which is executed as part of DHTML in a particular web browser while Perl is 
> general purpose programming language and has nothing to do with DHTML (you 
> need PerlScript for that)?

This isn't true. Microsoft have a tool called Windows Script Host, that
allows VB- (and Java-) scripts to run independently of any browser, or
anything like that. It is the official M$-recommended way of scripting
windows (they've finally admitted .bat files are useless).

To the OP: AS Perl is straightforward to install, and provided your
program's written cleanly (i.e. uses standard modules for stuff rather
than roll-your-own) I would expect relatively little trouble porting it.

Ben

-- 
           All persons, living or dead, are entirely coincidental.
ben@morrow.me.uk                                                  Kurt Vonnegut


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

Date: Fri, 03 Dec 2004 22:33:47 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: A problem with fork() and managing processes
Message-Id: <jql1r0tb34qgfu9g3udm8g7ji5tj8cjpgb@4ax.com>

On 03 Dec 2004 01:06:17 GMT, xhoster@gmail.com wrote:

>> Also, as far as the randomic persistence of non-zombie instances goes,
>> I *think* that it may be related to the process removal phase
>> beginning too early, possibly "interfering" with the "diffusion" one
>> which may not be terminated yet for some of the forked processes:
>
>You don't install the sig term handler until after the for loop.  The
>parent finishes all seven trips through the loop and starts killing its
>family.  But some members of the family maybe haven't quite finished their
>trips through the loop at the time they are sent a TERM by the parent.
>Since they haven't yet installed the handler, they don't execute the
>handler code.  So *their* children never get killed.  I think that just
>moving the handler assingment to before the for loop should fix the
>problem.

Thank you very much for the suggestion. Moving it before the loop now
seems the Right Thing(TM) anyway. But it didn't totally remove the
problem, even if it became certainly less frequent. So I simply left
the sleep() statement in place, and won't bother any more, especially
since the *real* code will have to do something similar anyway...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 03 Dec 2004 22:33:48 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: A problem with fork() and managing processes
Message-Id: <52m1r0d2p9ead0vvp7jju1uhrrlo5mdodh@4ax.com>

On 03 Dec 2004 00:50:30 GMT, xhoster@gmail.com wrote:

>>         kill 15, @family;
>>           waitpid $_, 0 for @family;
>
>Here you wait for your family.
>
>>         die "[$forked:$$] Stopping now: ",
>>             "signaled (@family)\n";
>>       };
>>
>>       while (1) {
>>         next if $forked;
>>         kill 15, @family;
>
>Here you don't.

As you can see by my other post eventually I realized/learned this
myself (with the help of Anno, of course!) In practice due to my
absymal ignorance on the subject I didn't even know it to be
necessary. I did it in the first snippet 'cause I thought it would
have been sensible to wait for one's family *before committing
suicide*. Hopefully now I'm slightly less ignorant!


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Fri, 03 Dec 2004 11:22:38 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Complex Search and Replace
Message-Id: <jgibson-005405.11223503122004@host70.newsfeeds.com>

In article <Ah1sd.64$3T2.21@trnddc04>,
 "Jürgen Exner" <jurgenex@hotmail.com> wrote:

> Glo Worm wrote:
> > Hello,
> >
> > How can I take a file such as
> >
> > abc'abc
> > abc\'abc
> > abc\\\'abc
> >
> > and use a Perl script to make it look like
> >
> > abc\'abc
> > abc\'abc
> > abc\'abc
> >
> > In any case I'd like for the first and second field to be delimited
> > with \'
> 
> You don't give much details about what 'abc' can be nor about what the 
> erronious possible delimeters can be in the original file (just listing 
> three examples is a bit meager).
> 
> What about a plain
>     s/\\*/\\/
> This does the job at least for your examples.

You forgot the quote character:

   s/\\*'/\\'/;

-- 
Jim Gibson


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

Date: 3 Dec 2004 13:40:29 -0800
From: jason@cyberpine.com
Subject: conditioning system shell output from within Perl - Noob
Message-Id: <ef0a04d7.0412031340.12810549@posting.google.com>

When I execute the folloing at the HPUX Posix shell

diffmsg=`scripts/cdiff.sh`
print $diffmsg

I get the echo output from that script.

However, inside Perl, apparently once the shell system call closes,
that environment variable is gone as $diffmsg never has anything in
it.

system "diffmsg=`scripts/cdiff.sh` ";
$diffmsg = ($ENV{'diffmsg'});

Am I correct in my findings?

Any easy way to be able to condition the output from this shell script
in perl? I'm hoping without having to open, read and close a file.

Thanks.


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

Date: Fri, 3 Dec 2004 14:19:58 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: conditioning system shell output from within Perl - Noob
Message-Id: <ed5782xium.ln2@goaway.wombat.san-francisco.ca.us>

On 2004-12-03, jason@cyberpine.com <jason@cyberpine.com> wrote:
> When I execute the folloing at the HPUX Posix shell
>
> diffmsg=`scripts/cdiff.sh`
> print $diffmsg
>
> I get the echo output from that script.
>
> However, inside Perl, apparently once the shell system call closes,
           ^^^^^^^^^^^
> that environment variable is gone as $diffmsg never has anything in
> it.

That's because once the system call is done, the shell where the
variable was set is also gone (if one was called).

> Any easy way to be able to condition the output from this shell script
> in perl? I'm hoping without having to open, read and close a file.

perldoc -q output.*system

--keith

-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom



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

Date: Fri, 3 Dec 2004 16:24:49 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: conditioning system shell output from within Perl - Noob
Message-Id: <slrncr1pth.2eb.tadmc@magna.augustmail.com>

jason@cyberpine.com <jason@cyberpine.com> wrote:

> However, inside Perl, apparently once the shell system call closes,
> that environment variable is gone as $diffmsg never has anything in
> it.


Yes, that is standard Unix process model stuff, the same with any
programming language.

A child cannot affect it's parent's environment.


> system "diffmsg=`scripts/cdiff.sh` ";

> Any easy way to be able to condition the output from this shell script
> in perl? 


Yes.


> I'm hoping without having to open, read and close a file.


Well you *are* going to have to open and read the documentation
for the system() function. 

I gotta wonder how it is that you haven't done that already...

It says right in there how to capture the output from external programs.


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


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

Date: Fri, 03 Dec 2004 17:38:47 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: conditioning system shell output from within Perl - Noob
Message-Id: <vNudner2hcNldy3cRVn-2g@adelphia.com>

jason@cyberpine.com wrote:

> Any easy way to be able to condition the output from this shell script
> in perl? I'm hoping without having to open, read and close a file.

As far as the environment variable being visible to the parent Perl app, 
that's a FAQ. Have a look at "perldoc -q environment".

But you don't need an environment variable at all - just capture the 
output of scripts/cdiff.sh directly. Backticks work in Perl the same way 
they do in your shell, so in Perl do:

my $diffmsg = `scripts/cdiff.sh`;

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Fri, 3 Dec 2004 23:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 5.25: How do I print to more than one file at once?
Message-Id: <coqrb5$it1$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

5.25: How do I print to more than one file at once?

    To connect one filehandle to several output filehandles, you can use the
    IO::Tee or Tie::FileHandle::Multiplex modules.

    If you only have to do this once, you can print individually to each
    filehandle.

        for $fh (FH1, FH2, FH3) { print $fh "whatever\n" }



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: 3 Dec 2004 15:01:30 -0800
From: mluvw47@gmail.com (Maverick Ieong)
Subject: Monitor a dos console perl program running
Message-Id: <d4b6522b.0412031501.52326913@posting.google.com>

Hi, 
  I have a perl script (script name: doingwork.bat) that doing some
work that take about 3-4 hour easily on the DOS console. Say output on
the dos console, like below..
c:\>doingwork.bat
== Build Working 1/10000
Build 1 == done.
Build 2 == done.
 ...
 ...
  
  Is that a way allow other people to see what doingwork.bat progress
have done from IE? I know using netmeeting can do it, but I just want
to connect the machine say..
http://mymachine.somedomain.com/doingwork.bat will tell me the above
progress from IE. Do I need to make the above script as CGI script or
how should I do it?

TIA.

Regards,
Mav


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

Date: Fri, 3 Dec 2004 12:51:00 -0700
From: Perl User <ravi@none.nowhere.com>
Subject: Obtaining length of binary string
Message-Id: <Pine.OSF.4.60.0412031245300.686786@manta.eller.arizona.edu>

Hi,
 	Here's my problem:

I read encrypted data from a server and save it in a variable. Now, I need 
to send this back to the server along with a number that tells how many 
bytes long the binary data is.

I've tried
$x = read_data_from_server($args);
$y = length $x;
send_data_to_server($x,$y);

I am not sure if the length function is the right way to count the number 
of bytes in the string $x. Can someone please show me how to do this?

Thanks a lot!


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

Date: 3 Dec 2004 12:47:29 -0800
From: binnyva@hotmail.com (Binny V A)
Subject: Re: Perl Books
Message-Id: <68cd8f94.0412031247.dfbeb7b@posting.google.com>

Hi Everybody,

I am the author of the said
tutorial(http://www.geocities.com/binnyva/code/perl/tutorial/index.html).
I must apologize for my errors. But then again you must see my 
point of view also. I have written a tutorial DON'T mean that 
I have completed the tutorial. A lot of polishing has to be 
done before completing it.

But I am to blame for most of the errors. Making spelling mistakes
the age of spell checkers are without excuse. So are many other 
mistakes that were made by me.

As many of you have already gussed, I am not a english is not my 
native tounge. So I am entitlled to a few errors. 

Anyway, thanks for the feedback. I will try to polish and then
publish the tutorial. If some of you could help me by proofreading
and by posting your suggetions, I would be very grateful.

One good thing is that I have learnt the meaning of the pharse
"If you really want to make an impression about something, 
do it wrong." ;-)

Once again thanking you,

Binny V A
http://www.geocities.com/binnyva


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

Date: 03 Dec 2004 13:21:04 -0800
From: Andy Glew <andy.glew@intel.com>
Subject: Re: Perl classes NOT in separate files
Message-Id: <q5i4qj3m62n.fsf@plxc0250.pdx.intel.com>

> > [Me, Andy Glew --- news@patten-glew.net]
> > print "Code befre interleaved package/classes\n";
> > {
> >    package A;
> >    sub new { bless {}; }
> >    sub bar { print "A"; }
> > }
> > print "Code between interleaved package/classes\n";
> > {
> >    package B;
> >    sub new { bless {}; }
> >    sub bar { print "B"; }
> > }

> > I've tried putting package more than once
> > in a file, with no luck. E.g. how do you
> 
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> What's the problem?  "No luck" is right there with "doesn't work".


Sorry.  The last time I tried this (multiple packages per file) was
many years ago (circa 1996-2000) on a much earlier version of Perl.  I
only vaguely remember that, but I think I did

      package A;
      ...
      package B;
      ...

instead of 

      {
         package A;
         ...
      }
      {
         package B;
         ...
      }

Whatever I did back then, I could not get it to work.


I realized, as I was writing the post, that embedding the package in
curly braces works.  It may even work without the curly braces,
but I prefer the curly block because it allows me to embed
the package right in the code - see below.

I thought that I had fixed my post to reflect this --- to now just be
a question "Is this the best way to do multiple packages in the same
file?"  But apparently I did not catch everything. Sorry.


So, is this the best way to embed packages in a file?

      {
         package A;
         ...
      }
      {
         package B;
         ...
      }

By the way, I like using the curly block because it allows me to place 
a package in the middle of code.  To my surprise

        sub bar {
                my $arg = shift;

                package foo {
                        ...
                }

                ...
        }

seems to work.

---

Follow-on question: what about nested packages
within the same file?  Or, nested packages period.

{
   package A;
   ...
   {
      package B;
      ...
   }
}

did *NOT* do what I, well, didn't really expect
but might have hoped for.

Even though nested like this, package B is defined
in the global scope.  I had been hoping that it
might be defined as A::B, i.e. nested.

I was hoping that I could use this so that 
I did not have to worry as much about namespace collisions.

E.g. 
{ 
    package A;
    { 
	package helper; 
	sub hello { print "A...helper\n";}
    }
}
helper::hello();
{ 
    package B;
    { 
	package helper; 
	sub hello { print "B...helper\n";}
    }
}
helper::hello();

Produces 
B...helper
B...helper


I.e. A's helper is defined over.  That is unfortunate.


-- 
---
Andy Glew

Potential bias: employed now by Intel
	past by AMD, Intel, Motorola, Gould ...
This post is personal, and is not the opinion of 
	any of my employers, past or present.


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

Date: 3 Dec 2004 12:59:12 -0800
From: jl_post@hotmail.com (J. Romano)
Subject: Re: Pipe input from a Text-File
Message-Id: <b893f5d4.0412031259.3d915e4c@posting.google.com>

glange@libero.it (Gerhard) wrote in message news:<bfd7a7ec.0412030530.3f387002@posting.google.com>...
> 
> My question is how can I "pipe" some numbers, which I've
> stored in a seperate Text-File "input.txt" to the PERL
> Script from the DOS Command-line ?
> I've tried this, but it don't work this way:
> C:\>type input.txt | add.pl


   You normally can't pipe output of one program to the command-line
of another, Gerhard.  However, there is a Unix utility called "xargs"
that allows you to do just that, but it's not normally found on Win32
platforms.

   You could always download it, but you can do exactly what you want
in Perl very easily with this command:

      C:\> perl -lne "system(qq/add.pl $_/)" input.txt

Explanation:

   * The -ne switches mean that the code that follows
     is to be run for each line of input.txt
   * The -l switch automatically chomp()s each line
     (so you don't have to)
   * The system() command runs the add.pl program
     with the parameters specified in a line of
     input.txt (which is exactly what you wanted)

   And finally, I recommend that you add a newline to the print
statement of your original program, otherwise all the output values
will print all together on one line (with no spaces in-between).

   I hope this helps, Gerhard.

   -- Jean-Luc


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

Date: Fri, 3 Dec 2004 19:32:48 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Pipe input from a Text-File
Message-Id: <0kr682-b44.ln1@osiris.mauzo.dyndns.org>


Quoth Tore Aursand <toreau@gmail.com>:
>
>       last unless ( defined && /\d/ );
>       $sum += $_;
>   }
>   print "$sum\n";
> 
> Should work, although it could have been better at checking if there is a
> real number (decimal or not).

Scalar::Util::looks_like_number

Ben

-- 
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based 
on the strictest morality.  [Samuel Butler, paraphrased]       ben@morrow.me.uk


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

Date: Fri, 03 Dec 2004 16:15:18 -0600
From: Spin <cNaOlSePbA@MvPeLtEsAtSaEr.com>
Subject: print FILE truncating input
Message-Id: <10r1pbkt8lbp8ab@corp.supernews.com>

This code:

open (FILE, ">>$path") or die "Unable to open file $!";
print "Result Type: ".$result_type."\n";
print get_lab_header($loc),"\n";
close (FILE) or die "Can't close file";

produces "BLOATY     REQID112004120316:06:30" on screen

This code (only adding "FILE" to above):

open (FILE, ">>$path") or die "Unable to open file $!";
print "Result Type: ".$result_type."\n";
print FILE get_lab_header($loc),"\n";
close (FILE) or die "Can't close file";

produces "BLOATY     REQID" on screen and "112004120316:06:30" in the file.

Why is it not putting the whole string (BLOATY...06:30) into the file?

TIA Caleb


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

Date: Fri, 03 Dec 2004 16:24:56 -0600
From: Spin <cNaOlSePbA@MvPeLtEsAtSaEr.com>
Subject: Re: print FILE truncating input
Message-Id: <10r1ptnbl1c2273@corp.supernews.com>

And this is the sub of interest:

sub get_lab_header {
# print "1. ",$_[0];
my $data = $_[0];
# my $data = unpack("a16"x(length($_[0])/16)."a*",$_[0]);
# print "2. ",$data;
# $data =~ tr/\0-\37\177-\377/./;
# print "3. ",$data;
my $visit_id = substr($data,22,20);# get/create Visit ID
$visit_id =~ s/^\s+//;	# strip whitespace off each end
$visit_id =~ s/\s+$//;
$visit_id = printf("%-10s", $visit_id); # pad string (right justified)
my $header_string = $visit_id;		# start header string
my $req_id = substr($data,124,7);
$req_id =~ s/^\s+//;
$req_id =~ s/\s+$//;
$req_id = printf("%-5s", $req_id);
$header_string .= $req_id;
my $date = "20".substr($data,13,2);
$date .= substr($data,11,2);
$date .= substr($data,9,2);
$header_string .= $date;
my $time = substr($data,15,2).":";
$time .= substr($data,17,2).":";
$time .= substr($data,19,2);
$header_string .= $time;
return $header_string;
}
Spin wrote:
> This code:
> 
> open (FILE, ">>$path") or die "Unable to open file $!";
> print "Result Type: ".$result_type."\n";
> print get_lab_header($loc),"\n";
> close (FILE) or die "Can't close file";
> 
> produces "BLOATY     REQID112004120316:06:30" on screen
> 
> This code (only adding "FILE" to above):
> 
> open (FILE, ">>$path") or die "Unable to open file $!";
> print "Result Type: ".$result_type."\n";
> print FILE get_lab_header($loc),"\n";
> close (FILE) or die "Can't close file";
> 
> produces "BLOATY     REQID" on screen and "112004120316:06:30" in the file.
> 
> Why is it not putting the whole string (BLOATY...06:30) into the file?
> 
> TIA Caleb


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

Date: Fri, 03 Dec 2004 22:41:19 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: print FILE truncating input
Message-Id: <jY5sd.52$mS4.15@trndny04>

Spin wrote:
> This code:
> 
> open (FILE, ">>$path") or die "Unable to open file $!";
> print "Result Type: ".$result_type."\n";
> print get_lab_header($loc),"\n";
> close (FILE) or die "Can't close file";
> 
> produces "BLOATY     REQID112004120316:06:30" on screen

No, it doesn't.  You haven't correctly quoted your screen output.  Your 
first 'print' statement above includes a newline, as does your second. 
Hence, your screen output must consist of 2 distinct lines.  Also 
(albeit more trivially) your output must begin with "Result Type:  ".

> 
> This code (only adding "FILE" to above):
> 
> open (FILE, ">>$path") or die "Unable to open file $!";
> print "Result Type: ".$result_type."\n";
> print FILE get_lab_header($loc),"\n";
> close (FILE) or die "Can't close file";
> 
> produces "BLOATY     REQID" on screen and "112004120316:06:30" in the file.
> 
> Why is it not putting the whole string (BLOATY...06:30) into the file?
> 

Because you haven't written your script to do that.  If you want 
everything to go into the file you must either (a) begin each print 
statement with 'print FILE' or (b) establish FILE as the default 
filehandle before the first print statement.  See:

     perldoc -f print
     perldoc -f select

Jim Keenan


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

Date: Fri, 03 Dec 2004 17:03:54 -0600
From: Spin <cNaOlSePbA@MvPeLtEsAtSaEr.com>
Subject: Re: print FILE truncating input
Message-Id: <10r1s6ofhv4rg5e@corp.supernews.com>

When including "FILE" in the print statement the output to screen is:

Result Type: C
BLOATY    REQID

And to file:

112004120316:56:42


Conversely, when not including "FILE", this prints to screen:

Result Type: C
BLOATY    REQID112004120316:58:50

And nothing prints to file.

What do I need to change to have

BLOATY    REQID112004120316:58:50

written to the file?

Caleb


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

Date: 3 Dec 2004 14:02:47 -0800
From: djcameron60616@yahoo.com (delfuego)
Subject: Question on loops and return values
Message-Id: <6b28e43f.0412031402.625c91eb@posting.google.com>

I  have a script below that is supposed to read in a list of microsoft
servers, and output the disk space (current and last), dates
(beginning and ending), and compute space growth in value and
percentage; to output file.  The question is this:  how do I get the
correct looping going on in my for loops (one is not getting the
machines, the other is not getting the drive letters; as well as any
other problems you can point out.  The files are listed below the
scriipt, although I plan to write out two additional columns, growth
value and growth rate.
ALL help is appreciated.
Thanks,

James

<script beow inline>

use lib "$ENV(HOME)/site/lib";		# occasionally perl whines about not
in a lib
no lib ".";
use warnings;
use Time::localtime;			# needed for tm and using that to get dates
use Time::tm;
use Win32API::Resources; 		# needed for drives and disk space

our @drive = Win32API::Resources::GetDrives();
our %space = Win32API::Resources::GetDriveSpace("$let:\\");
our $file = (<SD>,"growth.cvs");	# output data file
our $file2 = (<SD>,"machines.cvs");	# input data file
our $let = ['A-Z'];			# character value for drive letters
our $gvalue = 0;			# difference, should be positive
our $curr = 0;				# current disk space value
our $last = 0;  			# last disk space value
our $grate = 0;  			# growth rate percentage
our @line = "";  			# was going to be used for file looping
our $edate = "";  			# end date for run
our $sdate = "";  			# start date for run

# Mind you, we still need to loop this through machines in a list, but
# this will supposedly loop through the letters in the GetDrives
returns
open (file2,"+<"); # open machines input file for read
while <file2>  # loop while not eof in machines.cvs
{
  foreach $machine (<file2>)
  {
    print "The following are valid disk drives: @drive\n";
    foreach $let (@drive)
    {
      &space();
      &growth();
    }
  }
}

close file2;

sub space()
# This will return the space details available from ShowKeys in three
line format
{
  Win32API::Resources::ShowKeys("Drive Space:", 2, \%space);
}

sub growth()
# Reads in current value from file growth.cvs to be the value for
last, then
# the %DRVSpace becomes current's value.  After this, the dates are
set and
# we start computing the growth, giving growth difference and
percentage.
# Finally, all details are written to the appended file.
{
  open file or die "Cannot open data file for read\n"; 
  while <file>
  {
    $sdate = (read(file,"$junk," ",$edate," ",$junk," ",$junk) =
split);
    chop ($sdate);
    $last = (read(file,"$junk," ",$junk," ",$junk," ",$curr) = split);
    chop ($last);
  }
  close file;
  # we have the last and sdate variables, now we need the others
  my $edate = Time::tm(localtime(){$4,$5,$6});
  $curr = %DRVSpace;
  $last = eval { $curr / 5 }; # bogus value for testing, should be
file($curr)
  # now we sart computing
  $gvalue = eval { $curr - $last }; # growth rate difference
  $grate = eval { ($gvalue / $last) * 100 }; # growth rate percentage
  # time for a screen dump
  print "Date: $edate";
  print "Last: $last\tCurrent: $curr\tGrowth: $gvalue\tGrowth Rate:
$grate\n";
  # now to dump everything to the file
  open (file,"+>> ") or die "Cannot open data file for write\n";
  while <file>
  {
    print (file,"\n$sdate $edate $last $curr");
  }
  close file;
}

<files>

machines.csv
---------------
snoopy
linus
charlie
lucy
pigpen
freida

growth.csv
-----------
11-29-2004 11-30-2004 160 125 
11-30-2004 12-01-2004 125  75
12-01-2004 12-02-2004  75  50


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

Date: 03 Dec 2004 20:22:24 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: SQLite - problem connecting to database (or doing a select)
Message-Id: <yzdacsvmbkf.fsf@invalid.net>


"daniel kaplan" <nospam@nospam.com> writes:
> "Arndt Jonasson" <do-not-use@invalid.net> wrote in message
> news:yzdeki7mfri.fsf@invalid.net...
> 
> > I seem to find a fair number of those with dejanews.
> 
> am sure i am not the first, nor the last......and i am sure i will do it
> again myself, it's just happens....but i like the name....and will try not
> to do it again
> 
> as for whatever wilbur said (i noticed him in your reply)

Well, it was his article I was answering...


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

Date: Fri, 3 Dec 2004 15:54:14 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: SQLite - problem connecting to database (or doing a select)
Message-Id: <1102107356.714263@nntp.acecape.com>

"Arndt Jonasson" <do-not-use@invalid.net> wrote in message
news:yzdacsvmbkf.fsf@invalid.net...

> Well, it was his article I was answering...

oh yes, i know...i was just saying i will try to keep a control on the
dejanews...mine own that is




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

Date: 3 Dec 2004 11:16:08 -0800
From: swolf2@yahoo.com (Sven Wolf)
Subject: Re: testing for existence of an inline file with Inline::Files
Message-Id: <919461e0.0412031116.660e7824@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<copo7j$6o5$2@mamenchi.zrz.TU-Berlin.DE>...
> Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> > Sven Wolf <swolf2@yahoo.com> wrote:
> > > Hello,
> > > 
> > > I'm using Inline::Files, which allows me to put data after __FOO__ in
> > > a file and then to read it with "while (<FOO>) {...}" or @lines =
> > ><FOO>;
> > 
> > 
> > > I get a read-from-unopened-filehandle error if there is no section
> > > __MYCANDIDATE__ in the script.
> > > 
> > > Can someone suggest a test to apply before attempting to read?
> > 
> > 
> > The docs say that a package variable named $MYCANDIDATE will
> > exist if there is such a section. You can just look in the
> > symbol table to see if one by that name is there or not.
> > 
> > This seems to work for me:
> > 
> >    die 'no such section' unless exists $main::{MYCANDIDATE};
> 
> More generally, fileno( HANDLE) will be defined if and only of HANDLE
> is an open filehandle.  In particular,
> 
>     defined fileno( DATA)
> 
> will tell if there is an available __DATA__ or __END__ section.  I
> suppose that's how $MYCANDIDATE is set internally.
> 
> Anno

Thanks.  I'm getting an exception when trying this with a virtual
file.

use warnings;
use Inline::Files;
my $sec = 'FOO';

eval {
    print "$sec there\n" if defined fileno("main::$sec");
};
if ($@) {
    print "tried and caught $@\n";
}
__FOO__

yields
tried and caught Inline::Files::Virtual::FILENO not yet implemented at
test.pl line 6

Segmentation fault (core dumped)

I think the answer for me is just to turn off the warnings temporarily
and let Inline::Files go ahead and try to open the filehandle even if
it might not exist.

I suppose I might be behind the curve in Perl version (5.6.1) or
Inline::Files version (0.62) but those are constraints of my
environment.


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

Date: Fri, 3 Dec 2004 19:25:51 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: testing for existence of an inline file with Inline::Files
Message-Id: <v6r682-b44.ln1@osiris.mauzo.dyndns.org>


Quoth swolf2@yahoo.com (Sven Wolf):
> Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrncqvv0r.cmo.tadmc@magna.augustmail.com>...
> > Sven Wolf <swolf2@yahoo.com> wrote:
> > > Hello,
> > > 
> > > I'm using Inline::Files, which allows me to put data after __FOO__ in
> > > a file and then to read it with "while (<FOO>) {...}" or @lines =
> > ><FOO>;
> > 
> > 
> > > I get a read-from-unopened-filehandle error if there is no section
> > > __MYCANDIDATE__ in the script.
> > > 
> > > Can someone suggest a test to apply before attempting to read?
> > 
> > 
> > The docs say that a package variable named $MYCANDIDATE will
> > exist if there is such a section. You can just look in the
> > symbol table to see if one by that name is there or not.
> > 
> > This seems to work for me:
> > 
> >    die 'no such section' unless exists $main::{MYCANDIDATE};
> 
> Yes, that works for me, too.  The trick is making it work indirectly. 
> I have $inlinefile = 'MYCANDIDATE'.  Is there an expression in terms
> of the lhs?

Errr.... did you try

die "no such section' unless exists $main::{$inlinefile};

?

%main:: is just a hash with a silly name. Note that this comes under
symrefs, so be careful.

Ben

-- 
For far more marvellous is the truth than any artists of the past imagined!
Why do the poets of the present not speak of it? What men are poets who can
speak of Jupiter if he were like a man, but if he is an immense spinning
sphere of methane and ammonia must be silent? [Feynmann]     ben@morrow.me.uk


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

Date: Fri, 3 Dec 2004 16:17:10 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: testing for existence of an inline file with Inline::Files
Message-Id: <slrncr1pf6.2eb.tadmc@magna.augustmail.com>

Sven Wolf <swolf2@yahoo.com> wrote:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<copo7j$6o5$2@mamenchi.zrz.TU-Berlin.DE>...
>> Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
>> > Sven Wolf <swolf2@yahoo.com> wrote:

>> > > I get a read-from-unopened-filehandle error if there is no section
>> > > __MYCANDIDATE__ in the script.
>> > > 
>> > > Can someone suggest a test to apply before attempting to read?


>> >    die 'no such section' unless exists $main::{MYCANDIDATE};

>> More generally, fileno( HANDLE) will be defined if and only of HANDLE
>> is an open filehandle.  In particular,
>> 
>>     defined fileno( DATA)


> I'm getting an exception when trying this with a virtual
> file.


> tried and caught Inline::Files::Virtual::FILENO not yet implemented at
> test.pl line 6

> I think the answer for me is just to turn off the warnings temporarily


I think that is the LAST answer, to be used only when all other
possibilities have been eliminated.

Looks like Anno's idea is ahead of the module's implementation.  :-(

But what is wrong with my idea then?

(apart from the small chance of having chosen a scalar variable
 name identical to a data section name, in which case it wasn't I::F
 that made the symbol table entry.)


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


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

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


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