[19003] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1198 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 26 14:10:40 2001

Date: Tue, 26 Jun 2001 11:10:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993579015-v10-i1198@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 26 Jun 2001     Volume: 10 Number: 1198

Today's topics:
        Passing Shell variables <e.broeren@food-express.nl>
    Re: Passing Shell variables <kiseok7@yahoo.com>
    Re: Passing Shell variables (Anno Siegel)
    Re: Passing Shell variables <boa@aaanet.ru>
    Re: passing variables the 'right' way ctcgag@hotmail.com
    Re: Perl *is* strongly typed (was Re: Perl description) <joe+usenet@sunstarsys.com>
    Re: Perl to Convert Code (Buck Turgidson)
    Re: Perl to Convert Code <ren@tivoli.com>
    Re: Perl to Convert Code <ren@tivoli.com>
        Problem with displaying an output to a Window (Diem Trinh)
    Re: puzzled over fork() doing something different to bo ctcgag@hotmail.com
    Re: regular expression problem (Xtreme)
    Re: Script stops on multiple question marks (Sweth Chandramouli)
    Re: Script stops on multiple question marks (Sweth Chandramouli)
    Re: Script stops on multiple question marks <mjcarman@home.com>
        seek or sysseek? <davsoming@lineone.net>
    Re: seek or sysseek? <boa@aaanet.ru>
    Re: seek or sysseek? (Anno Siegel)
    Re: Troubleshooting a CGI Script nobull@mail.com
    Re: untie attempted while 1 inner references still exis nobull@mail.com
    Re: untie attempted while 1 inner references still exis <m.grimshaw@salford.ac.uk>
    Re: untie attempted while 1 inner references still exis (Anno Siegel)
        using strict <patelnavin@icenet.net>
    Re: using strict nobull@mail.com
    Re: using strict (Anno Siegel)
    Re: Why does this split not work? <buggs-clpm@splashground.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 26 Jun 2001 17:41:33 +0200
From: "Eugene" <e.broeren@food-express.nl>
Subject: Passing Shell variables
Message-Id: <9haafi$u1s$1@ncc1701.cistron.net>

Hello all,

I'm a newbie in perl and i have a question.
Is it possible to run a script and giving variables when you start it ( the
$1 and $2 variables)
For example:
perl mailer.pl  "Emailadresfrom@emailadres" "Emailadresto@emailadresto"
I want the variable $mailfrom in the mailer.pl to be $1 and $mailto $2

Is this possible ?


Thanx all




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

Date: Wed, 27 Jun 2001 00:53:49 +0900
From: "╠Х╠Б╪╝" <kiseok7@yahoo.com>
Subject: Re: Passing Shell variables
Message-Id: <9habdu$q6s$1@imsinews.kornet.net>

you can use @_ Arrays

like this :

#mailer.pl

@TO = @_;
# @_[0] is 'Emailadresfrom@emailadres'
# @_[1] is 'Emailadresto@emailadresto'

&mailto($text, $_) foreach (@TO);


"Eugene" <e.broeren@food-express.nl> wrote in message
news:9haafi$u1s$1@ncc1701.cistron.net...
> Hello all,
>
> I'm a newbie in perl and i have a question.
> Is it possible to run a script and giving variables when you start it (
the
> $1 and $2 variables)
> For example:
> perl mailer.pl  "Emailadresfrom@emailadres" "Emailadresto@emailadresto"
> I want the variable $mailfrom in the mailer.pl to be $1 and $mailto $2
>
> Is this possible ?
>
>
> Thanx all
>
>




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

Date: 26 Jun 2001 16:48:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Passing Shell variables
Message-Id: <9haecn$t7q$3@mamenchi.zrz.TU-Berlin.DE>

According to Eugene <e.broeren@food-express.nl>:
> Hello all,
> 
> I'm a newbie in perl and i have a question.
> Is it possible to run a script and giving variables when you start it ( the
> $1 and $2 variables)
> For example:
> perl mailer.pl  "Emailadresfrom@emailadres" "Emailadresto@emailadresto"
> I want the variable $mailfrom in the mailer.pl to be $1 and $mailto $2
> 
> Is this possible ?

Yes.  Look up @ARGV in perlvar.

Anno


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

Date: Tue, 26 Jun 2001 20:51:38 +0400
From: "Oleg Bakiev" <boa@aaanet.ru>
Subject: Re: Passing Shell variables
Message-Id: <9haejj$2k8f$1@pa.aaanet.ru>


"Eugene" <e.broeren@food-express.nl>
news:9haafi$u1s$1@ncc1701.cistron.net...
> I'm a newbie in perl and i have a question.
> Is it possible to run a script and giving variables when you start it
 the
> $1 and $2 variables)
> For example:
> perl mailer.pl  "Emailadresfrom@emailadres" "Emailadresto@emailadresto"
> I want the variable $mailfrom in the mailer.pl to be $1 and $mailto $2
>
> Is this possible ?
>
my ($mailfrom, $mailto) = @ARGV;
or
my $mailfrom = $ARGV[0];
my $mailto =  $ARGV[1];



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

Date: 26 Jun 2001 17:27:51 GMT
From: ctcgag@hotmail.com
Subject: Re: passing variables the 'right' way
Message-Id: <20010626132751.711$ia@newsreader.com>

mjd@plover.com (Mark Jason Dominus) wrote:

> This is done automatically in Perl for scalars.  When you write
>
>         foo($x)
>
> Perl internally passes a pointer to the value of $x.
> There is no benefit to passing foo(\$x) instead.

I learn something new every day.


> For very large arrays or hashes, there may be a speed benefit, since
>
>         foo(@a)
>         foo(%h)
>
> pass a very long list of scalars.  foo(\@a) and foo(\%h) may be faster.

Doesn't it actually pass a very long list of reference to scalars?  to
be consistant with the above?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
                       Usenet for the Web


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

Date: 26 Jun 2001 12:55:26 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Perl *is* strongly typed (was Re: Perl description)
Message-Id: <m33d8nrxj5.fsf@mumonkan.sunstarsys.com>

David Coppit <newspost@coppit.org> writes:

> How many decimal places before a difference becomes "meaningful"? Perl
> thinks my original example is "meaningful", and that's good enough for
> me:

No. Perl "stringifies" doubles according to your platform's precision,
which is usually around 15 decimal places on a 32 bit OS. Discrepancies
between numbers like 1 and .999999999999999 is simply due to round-off 
error.  It it the *programmer's* responsibility to determine a
reasonable level of precision when working with doubles.  Like C, Perl 
cannot, and will not, do this for you.

>   $a = 1/3;
>   $b = 1/3 . '';
> 
>   print "different\n" if $a * 3 != $b * 3;
                           ^^^^^^^^^^^^^^^^

No: "==" is only meaningful if $a and $b are int's , or at least nearly 
so (i.e. becomes an integer when multiplied by 10**$n, for some 
$n < machine's precision (15 on a 32 bit OS) ).

> Sure, you can "fix" this by doing:
> 
>   $a = 1/3;
>   $b = (sprintf "%.16g", 1/3) . '';
                     ^^

Not in general- I think 16 decimal places is beyond the precision of
your machine. It will probably work for 1/3, but it may not "work" for
other fractions. By stringifying the double on a 32 bit machine, you 
effectively reduce the precision from 15 places (with uncertainty in the 
16'th place) to 14 (now with uncertainty in the 15th place). You should
not be surprised if your calculations no longer agree to 15 decimal
places, and even if they did, a raw "==" is still inapropriate.

>   print "different\n" if $a * 3 != $b * 3;

  print "different\n" if sprintf("%.14g", $a*3 - $b*3) != 0;

or

  print "different\n" if abs($a*3 - $b*3) > 5e-15;

but *not*

  print "different\n" if sprintf("%.14f", $a*3) eq sprintf("%.14f", $b*3);

because this magnifies the effects of round-off errors:

  % perl -wle 'printf("%.14f\n%.14f\n", 9.4e-14, 9.6e-14)'
  0.00000000000009
  0.00000000000010

> But by doing this you are coercing stringified 1/3 into a type
> class ("stringified numbers with necessary accuracy") that is
> compatible with the "numeric" type class.

Sorry, I have no idea what you mean here.

> > > More recently, I ran into this problem trying to compare data
> > > structures using Storable. One data structure had a stringified
> > > version of a number. Of course the frozen data were not equivalent,
> > > even though they were both of the "scalar" type.

That should not be too surprising, since freeze() serializes perl's
internal representation of the scalar.  If you want to compare them
as Perl scalars, you should be comparing their thaw()ed representations
instead.

> >
> > Were the numbers floats or ints?
> 
> Either:
> 
>   use Storable qw (freeze);

    use Storable qw /freeze thaw/;
> 
>   $a = 1/3;
>   $b = 1/3 . '';
> 
>   $fa = freeze \$a;
>   $fb = freeze \$b;
> 
>   print "different\n" if $fa ne $fb;

    print "same\n" if ${thaw $fa} eq ${thaw $fb};

> 
>   $a = 1;
>   $b = 1 . '';
> 
>   $fa = freeze \$a;
>   $fb = freeze \$b;
> 
>   print "different\n" if $fa ne $fb;

    print "same\n" if ${thaw $fa} == ${thaw $fb};

HTH
-- 
Joe Schaefer     "Always forgive your enemies; nothing annoys them so much."
                                               -- Oscar Wilde



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

Date: 26 Jun 2001 10:14:34 -0700
From: jc_va@hotmail.com (Buck Turgidson)
Subject: Re: Perl to Convert Code
Message-Id: <f98999c8.0106260914.20444628@posting.google.com>

That's extremely helpful.  Thanks.  One other question.  If I want to
make it case-insensitive (some of our programmers code either way),
can you tell me what the syntax is?
 
Thanks again.





Philip Newton <pne-news-20010626@newton.digitalspace.net> wrote in message news:<dv6hjtoenrhic82binuupji9nolaho70jo@4ax.com>...
> On 26 Jun 2001 07:26:51 -0700, jc_va@hotmail.com (Buck Turgidson) wrote:
> 
> > I have a task in which I need to take source code, and globally change
> > some strings.  E.g. I need to change references to EMPL_RCD# TO
> > EMPL_RCD and BENEFITS_RCD# TO BENEFITS_RCD, and other such
> > conversions.
> >  
> > Ideally, I'd like to use one directory as input, and write out to
> > another directory.
> >  
> > I don't know too much about Perl, but I understand that it lends
> > itself to this task very well.
> >  
> > Could someone provide me with a very brief shell of what I need to do
> > to accomplish this?
> 
> Something like this should do what you want:
> 
>     #!/usr/bin/perl -wp
>     s/\bEMPL_RCD#/EMPL_RCD/g;
>     s/\bBENEFITS_RCD#/BENEFITS_RCD/g;
>     # ... add more if you want ...
>     # pattern:
>     # s/ original / replacement /g;
> 
> Then go into the directory with the input files and call the script
> (say, 'change.plx') something like this:
> 
>     perl -i '/otherdir/*' change.plx *
> 
> This will change the strings in each file "in-place" and leave the
> original, unmodified file in 'otherdir' (the other way around from what
> you said, but easier to implement quickly in Perl).
> 
> The \b before the pattern matches a non-word/word boundary. This way, it
> will only match if EMPL_RCD# is not preceded by a letter, digit, or
> underscore (so that e.g. ALL_EMPL_RCD# would not be matched). If that's
> not what you want, remove the \b.
> 
> Hope this helps.
> 
> Cheers,
> Philip


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

Date: 26 Jun 2001 09:58:36 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Perl to Convert Code
Message-Id: <m37kxz70f7.fsf@dhcp9-173.support.tivoli.com>

On 26 Jun 2001, ren@tivoli.com wrote:

>   close $trg_fh or die "Problem writing to $trg_fh, $!\n";

Oops...

    close $trg_fh or die "Problem writing to $target_dir/$file, $!\n";

Also, I like Philip's solution better.  I had forgotten that you could
change other things besides the extension with -i.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 26 Jun 2001 09:53:39 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Perl to Convert Code
Message-Id: <m3d77r70ng.fsf@dhcp9-173.support.tivoli.com>

On 26 Jun 2001, jc_va@hotmail.com wrote:

> I have a task in which I need to take source code, and globally
> change some strings.  E.g. I need to change references to EMPL_RCD#
> TO EMPL_RCD and BENEFITS_RCD# TO BENEFITS_RCD, and other such
> conversions.
>  
> Ideally, I'd like to use one directory as input, and write out to
> another directory.
>  
> I don't know too much about Perl, but I understand that it lends
> itself to this task very well.
>  
> Could someone provide me with a very brief shell of what I need to
> do to accomplish this?
> 
> Thanks.

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

my @strings = qw/EMPL_RCD BENEFITS_RCD/;
my $source_dir = "/some/dir";
my $target_dir = "/some/other/dir";

opendir my $src_dh, $source_dir
  or die "Could not read $source_dir, $!\n";
while(my $file = readdir $src_dh) {
  next unless -f "$source_dir/$file";
  open my $src_fh, "<", "$source_dir/$file"
    or die "Could not read $source_dir/$file, $!\n";
  open my $trg_fh, ">", "$target_dir/$file"
    or die "Could not create $target_dir/$file, $!\n";
  while(<$src_fh>) {
    for my $string (@strings) {
      s/(?<=\b$string)#//g;
    }
    print $trg_fh $_;
  }
  close $trg_fh or die "Problem writing to $trg_fh, $!\n";
  close $src_fh;
}
closedir $src_dh;
__END__

-- 
Ren Maddox
ren@tivoli.com


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

Date: 26 Jun 2001 08:52:49 -0700
From: dtrinh2@yahoo.com (Diem Trinh)
Subject: Problem with displaying an output to a Window
Message-Id: <d56e82e4.0106260752.52fe58bf@posting.google.com>

I have this MENU program as GUI type that has a button READ MEDIA and
a displayed window underneat it.  I also created an input program
HELLO.cpp which is written in C++ that prints out the word "Hello" 20
times.  Each time it prints out one, it needs to pause for 2 seconds
then prints the next one out.

In the code of my "Menu" program, I have HELLO.cpp as an input file. 
My goal is when I press the button READ MEDIA, the output of HELLO
program needs to be displayed as one word after another (with 2
seconds paused between) in the window.
I tried to use exec command but it still doesn't work.  Please give me
help if you have any other solution.
Regards,


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

Date: 26 Jun 2001 17:44:30 GMT
From: ctcgag@hotmail.com
Subject: Re: puzzled over fork() doing something different to book example
Message-Id: <20010626134430.904$Rw@newsreader.com>

Mark Grimshaw <m.grimshaw@salford.ac.uk> wrote:
>
> ok - removing the -l switch has solved the 'half-execution'.  How do I
> force the parent to execute first?

Violence is not the answer.

Why do you want the parent to execute first?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
                       Usenet for the Web


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

Date: 26 Jun 2001 10:02:03 -0700
From: lxl22@visto.com (Xtreme)
Subject: Re: regular expression problem
Message-Id: <91ff860e.0106260902.4f19d6e1@posting.google.com>

Ren Maddox <ren@tivoli.com> wrote in message news:<m3ofrg9l8y.fsf@dhcp9-173.support.tivoli.com>...
> On 22 Jun 2001, lxl22@visto.com wrote:
> 
> > jacklam@math.uio.no (Peter J. Acklam) wrote in message
> > news:<cxclmmk388v.fsf@masterblaster.uio.no>...
> >> lxl22@visto.com (Xtreme) wrote:
> >> 
> >> > Assuming I have a string of the form "a_b_b_c" in which I don't
> >> > know how many "b_" substrings it has, how can I, in one single
> >> > s/// line replace every b_ for a "x_"?  My main problem is that
> >> > I don't know how to tell the re engine how to replace it the
> >> > same number of times as it occurred.
> >> 
> >>     s/b_/x_/g;
> > 
> > Thanks, Peter.  I had forgotten to mention that a,b and c can each be
> > distinct or the same -- I don't know ahead of time, and that I don't
> > want to replace a or c (i.e. not the first or last in the string).  I
> > figured it out in the mean time by going through (of all things) the
> > faq:
> > s/\G_b_/_x_/g;
> > I still don't really grasp the \G, but it works!
> 
> Wow.
> 
> I'm not sure what's going on there, as \G does not appear to have a
> defined behavior in a global substitute.  And the behavior it exhibits
> certainly isn't what I would expect.  In fact, the behavior I see
> doesn't achieve your stated goal:

Hmmm...  Maybe it is undefined behaviour.  Thanks for pointing it out.
 It did work, though.

> perl <<'__END__'
> $_ = "b_b_b_b_b_b";
> s/\G_b_/_x_/g;
> print "$_\n";
> __END__
> b_b_b_b_b_b
> 
> Skipping the whole \G issue, here is a solution that I believe does
> achieve your stated goal:
> 
> perl <<'__END__'
> $_ = "b_b_b_b_b_b";
> s/(?<=_)b(?=_)/x/g;
> print "$_\n";
> __END__
> b_x_x_x_x_b
> 
> It actually goes a bit overboard on the advanced regex features, but
> I'm a bit partial to only replacing the part you actually want to
> change.  It just feels more maintainable.  If at some point you change
> to "a-b-b-b-b-c", then you only have to change the match portion,
> which you would expect to have to change.  Removing the unnecessary
> dependency in the replacement string seems like a good thing.

Ahh!  This is precisely what I was looking for!  I wasn't very
familiar with the advanced regex features, but having taken a look at
what you suggested, it all makes sense!

Thanks!


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

Date: Tue, 26 Jun 2001 15:15:04 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Script stops on multiple question marks
Message-Id: <YF1_6.16300$Ga.2338395@news1.rdc1.md.home.com>

In article <m3n16v73wz.fsf@dhcp9-173.support.tivoli.com>,
Ren Maddox  <ren@tivoli.com> wrote:
>I'm confused... if "etre???" should only match "etre" then what is the
>point of the "?"-s?
[snip]
>I'm still not clear on exactly what you are trying to achieve.  If you
>want to ignore question marks, just use "tr/?//d" to strip them out.
>If you want to match literal question marks, change your regex to
>"/< */\Q$temp_response\E *>/".  If you want something different,
>please elaborate.
	I think that his problem is that the question marks are 
coming in from user input (e.g. a student who isn't sure of his answer 
typing "etre???" at the prompt); he would like for that to not match, but
instead his script hangs.  Normally, when faced with that string 
interpolated into a regex, perl should die with something like

/etre???/: nested *?+ in regexp at -e line 1.

	, unless the OP is somehow catching that error and not 
dealing with it properly.  From what he gives us, though, I can't see any
reason that that would be happening.

	-- Sweth.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: Tue, 26 Jun 2001 15:39:10 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Script stops on multiple question marks
Message-Id: <y02_6.16422$Ga.2342519@news1.rdc1.md.home.com>

In article <f5d27ac9.0106251019.5a9ce62c@posting.google.com>,
Darren Spidell <dspidell@mta.ca> wrote:
>I have a Perl script that compares feilds in Mysql tables for correct
>responses using a regular expresion (part of a French assessment). One
>table contains the user responses, the other contains possible correct
>answers. If there is a match a variable gets incremented. The user's
>response gets printed as HTML whether correct or not, so the evaluator
>can see all student responses.
>
>The problem is: If a response contains a string of 3 or more question
>marks, the script simply stops. The section of code is below.
>
>if (($i > $start_value+$part_1_num)&($i <= $start_value+$part_2_num))
>#Checks to see which part of the assessment the current question is in
>  {
>    print "$response[$i], ";
>    my $temp_answer = $answers[$i-$start_value];
>    $temp_response = $response[$i];
>    if ($temp_answer =~ /< *$temp_response *>/)
>    {
>      $part_2++;
>    }
>  }
>
>If the response is "etre???", the script prints "etre???," then quits.
>It seems to stop when it hits the regular expression.
	I respond to your actual question elsewhere; I was just also
wondering if you had considered using different data structures to store
your info.  You could fairly easily build your question list as an array
of hashes of other things, along the lines of

@questions_by_section = (
   {
      'score' => 0
      ,'list' => []
   }
   ,{
      'score' => 0
      ,'list' => [
         {
            'question' => "What is the infinitive of the verb for 'to be'?"
            ,'answer'  => "etre"
         }
         , {
            'question' => "What do you call the little pointy hat thing that "
               . "should have been on the first 'e' in the previous answer?"
            ,'answer'  => "circumflex"
         }
      ]
   }
   ,{
      'score' => 0
      ,'list' => [
         {
            'question' => "This is some other question in section two."
            'answer'   => "Statement--Two, Love."
         }
      ]
   }
);

	.  Then you stuff your responses into the same hash as the
question, and your logic above becomes much simpler (or at least much more
readable and maintainable):

for my $section (@question_by_section) {
   for my $question ($section->{'list'}) {
      $question->{'response'} eq $question->{'answer'}
         and $section->{'score'}++
   };
};

	.  That doesn't give you the number list of all of the 
responses as your original did, but that would be easy to add; it also
wouldn't be too hard to change the response item for each question into a
hash that keyed off of student name or something similar, so that you could
store all of the responses in the same structure, if you weren't just running
through this serially.

	-- Sweth.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: Tue, 26 Jun 2001 09:47:49 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Script stops on multiple question marks
Message-Id: <3B38A095.67FCDE4F@home.com>

Darren Spidell wrote:
> 
> Ren Maddox <ren@tivoli.com> wrote in message
> news:<m3sngo8cqm.fsf@dhcp9-173.support.tivoli.com>...
>
>> On 25 Jun 2001, dspidell@mta.ca wrote:
>>
>>> If a response contains a string of 3 or more question marks, the
>>> script simply stops.
>>>
>>>     if ($temp_answer =~ /< *$temp_response *>/)
>>>
>>> If the response is "etre???", the script prints "etre???," then
>>> quits.  It seems to stop when it hits the regular expression.
>>
>> Are you intending the pattern to allow special regex characters?
>> [...] If you don't want it to be special, use quotemeta() or
>> "\Q".
> 
> I don't want the pattern to to allow special characters other
> than "<", ">" and spaces.

Then you need to disable metachars for that part of your pattern:

if ($temp_answer =~ /< *\Q$temp_response\E *>/)

as Ren suggested.

> The really strange thing about it is it works fine if the user puts
> one or two question marks. It doesn't match, but it shouldn't. When I
> say it works, I mean the script continues to be processed. With 3
> question marks, the script stops.

That's because '?' and '??' are valid, but '???' isn't. It sends the 
regex engine into never-never land. Observe:

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

my $x = 'foo???';
$_ = '< foo >';

print "A\n";

if (/< *$x *>/) {
    print "B1\n";
}
else {
    print "B2\n";
}

print "C\n";

__END__
/< *foo??? *>/: nested *?+ in regexp at foo.pl line 10.
A

You should have seen a similar error for your script, printed to 
wherever your STDERR is going. (A logfile?)

Adding 'use diagnostics' gives (marginally) clearer results:

A
Uncaught exception from user code:
	/< *foo??? *>/: nested *?+ in regexp at foo.pl line 11.

-mjc


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

Date: Tue, 26 Jun 2001 17:58:38 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: seek or sysseek?
Message-Id: <tjhfdjl846n43e@corp.supernews.co.uk>

perldoc -f seek
says that If you want to position file for `sysread()' or
`syswrite()', don't use `seek()' -- buffering makes its
effect on the file's system position unpredictable and
non-portable. Use `sysseek()' instead.

OK! so which is appropriate here?
I'm wanting to check if email addresses already exist.

open (EMAILS, ">>","address.txt") or die ("Can't open $emails: $!");
flock (EMAILS, 2);
sysseek (EMAILS, 0, 0); # or seek?

my $found = 0;
while (<EMAILS>) {
  chomp;
  if (/^$email{'address'}$/i) {
    $found++;
    last;
  }
}

if ($found) {
 $errormessage = "The address you entered, <B>$email{'address'}</B> is
already in our mailing list";
} else {
  sysseek (EMAILS, 0, 2); # or seek?
  print EMAILS "$email\n";
}

close (EMAILS);

--
David Soming
'Just a head-banger- doing what I do best'
______________




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

Date: Tue, 26 Jun 2001 20:55:17 +0400
From: "Oleg Bakiev" <boa@aaanet.ru>
Subject: Re: seek or sysseek?
Message-Id: <9haeqh$2mb6$1@pa.aaanet.ru>


"David Soming" <davsoming@lineone.net> сообщил/сообщила в новостях
следующее: news:tjhfdjl846n43e@corp.supernews.co.uk...
> perldoc -f seek
> says that If you want to position file for `sysread()' or
> `syswrite()', don't use `seek()' -- buffering makes its
> effect on the file's system position unpredictable and
> non-portable. Use `sysseek()' instead.
>
> OK! so which is appropriate here?

seek is for print and <HANDLE>
sysseek is for sysread and syswrite





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

Date: 26 Jun 2001 17:00:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: seek or sysseek?
Message-Id: <9haf2q$t7q$4@mamenchi.zrz.TU-Berlin.DE>

According to David Soming <davsoming@lineone.net>:
> perldoc -f seek
> says that If you want to position file for `sysread()' or
> `syswrite()', don't use `seek()' -- buffering makes its
> effect on the file's system position unpredictable and
> non-portable. Use `sysseek()' instead.

The implication is supposed to be: Unless you are using sysread()
or syswrite(), use seek().

> OK! so which is appropriate here?
> I'm wanting to check if email addresses already exist.
> 
> open (EMAILS, ">>","address.txt") or die ("Can't open $emails: $!");
> flock (EMAILS, 2);
> sysseek (EMAILS, 0, 0); # or seek?
> 
> my $found = 0;
> while (<EMAILS>) {
>   chomp;
>   if (/^$email{'address'}$/i) {
>     $found++;
>     last;
>   }
> }
> 
> if ($found) {
>  $errormessage = "The address you entered, <B>$email{'address'}</B> is
> already in our mailing list";
> } else {
>   sysseek (EMAILS, 0, 2); # or seek?
>   print EMAILS "$email\n";
> }
> 
> close (EMAILS);

You're not using sysread or syswrite, so use seek.

Anno


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

Date: 26 Jun 2001 17:52:42 +0100
From: nobull@mail.com
Subject: Re: Troubleshooting a CGI Script
Message-Id: <u93d8n2nfp.fsf@wcl-l.bham.ac.uk>

mike <mikes@escape.com> writes:

>     I am trying to get started in learning some CGI scripting.

I suggest you get a book or tutorial.

> In the program I basically have:
> 
> #!/usr/bin/perl
> rename(1111,2222)

That is not a CGI script.  A CGI script is one whose interface (inputs
and outputs) that conform to the CGI standard. That does not.
 
Try a test program that is a CGI script.  Examples of CGI scripts
written in Perl can be found... well just about everywhere.

The simplest CGI script is:

#!/usr/bin/perl
print "Content-type: text/plain\n\nHello world";

For anything more complex I'd suggest you look into the Perl CGI module.

>   I get the error message: premature end of script headers in the
> error_log  file.

This means the output from your script ended before the end of the CGI
headers.  That would be because your script did not send any CGI headers.

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


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

Date: 26 Jun 2001 17:51:23 +0100
From: nobull@mail.com
Subject: Re: untie attempted while 1 inner references still exist
Message-Id: <u94rt32nhw.fsf@wcl-l.bham.ac.uk>

Mark Grimshaw <m.grimshaw@salford.ac.uk> writes:

> I need the return for $dbobj->sync();

Is there any particular reason you don't want to say
tied(%USER)->sync(); ?

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


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

Date: Tue, 26 Jun 2001 18:18:58 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: untie attempted while 1 inner references still exist
Message-Id: <3B38C402.42AF1C07@salford.ac.uk>



nobull@mail.com wrote:
> 
> Mark Grimshaw <m.grimshaw@salford.ac.uk> writes:
> 
> > I need the return for $dbobj->sync();
> 
> Is there any particular reason you don't want to say
> tied(%USER)->sync(); ?
> 
> --
>      \\   ( )
>   .  _\\__[oo
>  .__/  \\ /\@
>  .  l___\\
>   # ll  l\\
>  ###LL  LL\\

don't know.  Anyway, didn't know I could do that - thanks.  Is there any
advantage other than not having to explictly return and collect the
tie() object?


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

Date: 26 Jun 2001 17:32:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: untie attempted while 1 inner references still exist
Message-Id: <9hagv9$t7q$7@mamenchi.zrz.TU-Berlin.DE>

According to Mark Grimshaw  <m.grimshaw@salford.ac.uk>:
> 
> 
> nobull@mail.com wrote:
> > 
> > Mark Grimshaw <m.grimshaw@salford.ac.uk> writes:
> > 
> > > I need the return for $dbobj->sync();
> > 
> > Is there any particular reason you don't want to say
> > tied(%USER)->sync(); ?
> > 
> > --
> >      \\   ( )
> >   .  _\\__[oo
> >  .__/  \\ /\@
> >  .  l___\\
> >   # ll  l\\
> >  ###LL  LL\\
> 
> don't know.  Anyway, didn't know I could do that - thanks.  Is there any
> advantage other than not having to explictly return and collect the
> tie() object?

I think the particular error (well, warning) you ran into is a good
reason not to keep copies of a tied object around and to rely on tied()
instead.  The difference is a bit like the difference of using length()
on a string instead of keeping it in an extra variable.  Whenever
you have the string, you know how to get its length, and whenever you
have a tied variable you can have its tied object as well.  Some pervert
may even have gone and re-tied your variable, then where would you be...

Anno




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

Date: Tue, 26 Jun 2001 15:31:06 +0530
From: "Aman Patel" <patelnavin@icenet.net>
Subject: using strict
Message-Id: <9habt4$cs3m5$1@ID-93885.news.dfncis.de>

"In short, does the use strict pragma add load the to perl
interpreter/compiler..."

If my script is NOT using strict pragma, but compiles and runs perfectly if
done under use strict pragma, will there be any performance loss if i add
'use strict;' at the top of my script.




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

Date: 26 Jun 2001 17:49:18 +0100
From: nobull@mail.com
Subject: Re: using strict
Message-Id: <u97kxz2nld.fsf@wcl-l.bham.ac.uk>

"Aman Patel" <patelnavin@icenet.net> writes:

> "In short, does the use strict pragma add load the to perl
> interpreter/compiler..."

In short, no/yes.

In long... (and painful detail) see the thread that followed when this
question was posted on 24th May by "Leo" <leapius@hotmail.com>.

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


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

Date: 26 Jun 2001 17:16:49 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: using strict
Message-Id: <9hag21$t7q$5@mamenchi.zrz.TU-Berlin.DE>

According to Aman Patel <patelnavin@icenet.net>:
> "In short, does the use strict pragma add load the to perl
> interpreter/compiler..."
> 
> If my script is NOT using strict pragma, but compiles and runs perfectly if
> done under use strict pragma, will there be any performance loss if i add
> 'use strict;' at the top of my script.

Hardly.  Strictures only change the compile-time behavior, at run-time
there is no difference.  Even switching on warnings, which do change
the run-time behavior has no significant effect.

Of course, you can write code without using "strict" that won't compile
with it.  But the hacks that strict forbids aren't efficiency hacks.
You can save a bit of programmer time on small throw-away scripts
when you don't declare your variables.  You can also use symrefs and
scare the hell out of your fellow programmers.  Otherwise, there's not
much to be gained.

Anno


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

Date: Thu, 21 Jun 2001 07:21:00 +0200
From: Buggs <buggs-clpm@splashground.de>
Subject: Re: Why does this split not work?
Message-Id: <9gs044$s55$04$1@news.t-online.com>

tuxy wrote:

> Hi Ren:
> 
> I solved the problem. I went to a box with Perl 5.004 and botta-bing
> botta-boom just as I suspected, my code is pristine, it's Perl 5.6
> that's wacked. Apparently. Anyhow, now I either have to re-write this
> algorithm in something 5.6-friendly, or  have to revert to 5.004 on this
> other box. Neither prospect is overly appealing.
> 
> A little surprizing too that in a forum this large, none of the guru's
> would chime in with "oh split has some serious problems in 5.6".... That
> message would have saved me many hours of study and experimentation. Oh
> well what can I expect for free LOL..


Really sorry that you think you have to rewrite
the whole ( w h o l e ) line of "algorithm",
because you believe that 5.6 ships a broken split,
which causes random errors throughout your programm.

Oh and 5.6 has some serious ( even serial )
problems with you not presenting it a file
which it can understand.

Indeed LOL.


Buggs



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

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.  

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


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