[18779] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 947 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 21 09:05:39 2001

Date: Mon, 21 May 2001 06:05:10 -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: <990450309-v10-i947@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 21 May 2001     Volume: 10 Number: 947

Today's topics:
        [Mac] Perceps on Macintosh? (Paul-Michael Agapow)
        Array slice: how about the remainder? <johnlin@chttl.com.tw>
    Re: Array slice: how about the remainder? nobull@mail.com
    Re: Array slice: how about the remainder? (Anno Siegel)
    Re: Closure: which variable does it refer to? <ilya@math.ohio-state.edu>
        Function renaming and arguments replacing in c source c <federico@carmen.se>
    Re: garbage collection in perl (Kevin Reid)
    Re: Hash: keys to variable names, or variable names to  <koos_pol@nl.compuware.com.NOJUNKMAIL>
        Inserting data at the beginning of a file? <mlaw@talk21.comNOSPAM>
    Re: Inserting data at the beginning of a file? nobull@mail.com
    Re: Inserting data at the beginning of a file? <admin@the-piper.net>
    Re: Inserting data at the beginning of a file? <mlaw@talk21.comNOSPAM>
        Need help on formatting output <admin@the-piper.net>
    Re: Need help with regexp and returned data. <goldbb2@earthlink.net>
        Newbie perl CGI question <hmacdonald@europarl.eu.int>
        newbie Question PERL <rajesh_gupta@mailcity.com>
        password protection! <lutz@imas-international.com>
    Re: Perl icon in Windows- reminder please <bart.lateur@skynet.be>
        print function <Rene.Scheibe@gmx.net>
    Re: print function <bart.lateur@skynet.be>
    Re: Problems password protecting CGI Script <mlaw@talk21.comNOSPAM>
    Re: Problems password protecting CGI Script <mlaw@talk21.comNOSPAM>
    Re: Problems password protecting CGI Script (Gwyn Judd)
    Re: System Call within Daemon - TAKE 2 <goldbb2@earthlink.net>
    Re: time of a file (Bernard El-Hagin)
    Re: time of a file (Matt Williams)
    Re: Urgent: CGI program wanted <ellison@holzerath.de>
    Re: Why can't I localize a lexical variable? <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 21 May 2001 10:46:59 +0100
From: p.agapow@ic.ac.uk (Paul-Michael Agapow)
Subject: [Mac] Perceps on Macintosh?
Message-Id: <1etnlbs.1wkxy4a1jfr8z5N%p.agapow@ic.ac.uk>


Hiya,

The subjectline says it all: I'm trying to get Perceps running on a Mac,
and due in part to my very rusty Perl skills and in part to the lack of
a convenient CLI on the Mac, it's turning into a bit of an untidy task.
As notes inside the Perceps source indicate people used it on the Mac,
does anyone have any tips? Especially a flexible way of passing the
commandline to the Perceps script.

-- 
Paul-Michael Agapow (p.agapow@ic.ac.uk), Biology, Imperial College
"Pikachu's special power is that he's monophyletic with lagomorphs ..."


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

Date: Mon, 21 May 2001 18:22:02 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Array slice: how about the remainder?
Message-Id: <9eaq4b$pej@netnews.hinet.net>

Dear all,

I've been asked a quite interesting question.

my @array = <NAMELIST>;
my @chosen = (0,3,5,7,21,35,63,66,68);
my @go_picnic = @array[@chosen];  # those who are chosen go picnic
my @stay_home = @array[???????];  # those who are not chosen stay home

It's convinent to have array slice syntax to get partial of an array.
But what about the remainder (also partial of the array)?

The solution I can think of is:

my @not_chosen = grep {!grep($_,@chosen)} 0..$#array;
my @stay_home = @array[@not_chosen];

There must be a better way...  Could you help?

Thank you very much.

John Lin





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

Date: 21 May 2001 12:24:06 +0100
From: nobull@mail.com
Subject: Re: Array slice: how about the remainder?
Message-Id: <u9zoc7aqsp.fsf@wcl-l.bham.ac.uk>

"John Lin" <johnlin@chttl.com.tw> writes:

> I've been asked a quite interesting question.

We can always rely on a John Lin initiated thread to contain an
interesting question!

> my @not_chosen = grep {!grep($_,@chosen)} 0..$#array;
> my @stay_home = @array[@not_chosen];

That won't work, you meant:

my @not_chosen = grep {my $x=$; !grep($_ eq $x,@chosen)} 0..$#array;
 
This is pathologically inefficient (O(n**2)).

> There must be a better way...  Could you help?

My first reaction is to use the usual Perl idiom for complementing a
set...

my %not_chosen;
undef @not_chosen{0..$#array};
delete @not_chosen{@chosen};
# Can, of course, skip sort() if @stay_home order unimportant
my @stay_home = @array[sort { $a <=> $b } keys %not_chosen];
__END__

Probably better to do...

# Can, of course, skip sort() if @chosen known to be pre-sorted
my @chosen_copy = sort { $a <=> $b } @chosen;
my @not_chosen = grep {
    $_ != $chosen_copy[0] ||
	do { shift @chosen_copy; 0 } 
} 0..$#array;
my @stay_home = @array[@not_chosen];
__END__
-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 21 May 2001 12:37:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Array slice: how about the remainder?
Message-Id: <9eb26m$rk0$1@mamenchi.zrz.TU-Berlin.DE>

According to  <nobull@mail.com>:
> "John Lin" <johnlin@chttl.com.tw> writes:
> 
> > I've been asked a quite interesting question.
> 
> We can always rely on a John Lin initiated thread to contain an
> interesting question!
> 
> > my @not_chosen = grep {!grep($_,@chosen)} 0..$#array;
> > my @stay_home = @array[@not_chosen];
> 
> That won't work, you meant:
> 
> my @not_chosen = grep {my $x=$; !grep($_ eq $x,@chosen)} 0..$#array;
>  
> This is pathologically inefficient (O(n**2)).
> 
> > There must be a better way...  Could you help?
> 
> My first reaction is to use the usual Perl idiom for complementing a
> set...
> 
> my %not_chosen;
> undef @not_chosen{0..$#array};
> delete @not_chosen{@chosen};
> # Can, of course, skip sort() if @stay_home order unimportant
> my @stay_home = @array[sort { $a <=> $b } keys %not_chosen];
> __END__
> 
> Probably better to do...
> 
> # Can, of course, skip sort() if @chosen known to be pre-sorted
> my @chosen_copy = sort { $a <=> $b } @chosen;
> my @not_chosen = grep {
>     $_ != $chosen_copy[0] ||
> 	do { shift @chosen_copy; 0 } 
> } 0..$#array;
> my @stay_home = @array[@not_chosen];
> __END__

 ...or use a bit array to complement the set:

    my $aux = '';
    vec( $aux, $_, 1) = 1 for @chosen;
    my @stay_home = @array[ grep vec( ~ $aux, $_, 1), 0 .. $#array];

(I didn't bother with sort, why bring it up?)

Anno


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

Date: 21 May 2001 10:25:44 GMT
From: Ilya Zakharevich <ilya@math.ohio-state.edu>
Subject: Re: Closure: which variable does it refer to?
Message-Id: <9eaqf8$bvd$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Joe Schaefer 
<joe+usenet@sunstarsys.com>], who wrote in article <m3d793uv56.fsf@mumonkan.sunstarsys.com>:
> > The compiled form of a closure differs from usual subroutines by one
> > status bit only.  However, calculating a reference to a usual
> > subroutine (including anonymous ones - done in: sub {12}) is a simple
> > operation of creating a scalar of the type "reference".  Taking a
> > reference to a closure is much more involved: the subroutine "context"
> > (=scratchpad) is duplicated (and recalculated) at this moment.  The
> > generated reference variable contains a pointer to the new context.
> 
> This distinction is observable by looking at the CODE's "address",
> right?

I hope so.

> So is the following a "context recalculation" bug?
> 
> #!/usr/bin/perl -wl
>   use strict;
>   $a = foo();
> 
>   {
>     my $x = "bar";
>     sub foo {
>         # $x;                   # not so useless :-)
> 	return sub {$x};
>     }
>   }
> 
>   $b = foo();
> 
>   print $a->();
>   print $b->();
> 
> __END__
> 
> Output:
> bar
> Use of uninitialized value at /tmp/try.pl line 16.

Behaves as one may expect.  $a references the initial $x.  It is
undefined until the line $x = "bar" is executed (and `print $a->()'
behaves likewise until this moment).  So there is no problem with the
behaviour of $a.

$b references $x after the block containing $x is left.  During
going-out-of-scope of $x the "recycling" [1] is done, since the refcount
of $x is larger than 1 at this moment.  Hence $x becomes a new
undefined Perl value.  So there is no problem with the
behaviour of $b too.

[1] See my message of several days ago.

Hope this helps,
Ilya


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

Date: 21 May 2001 14:53:01 +0200
From: Federico Hernandez <federico@carmen.se>
Subject: Function renaming and arguments replacing in c source code
Message-Id: <rw4ruesw2a.fsf@gibraltar.carmen.se>

Hi,

I was wondering if there is some perl based script around that can be
used to rename functions and replace arguments in c source code?

E.g. we have the function call

foo( oogle, foogle)

that should be replaced by the function call

bar( corge, grault, foogle, flarp)

where corge corresponds to oogle and grault and flarp are extra new
arguments.

What I have for each function is the old/new name and the
corresponding changes in the argument list.

Greetings
Federico


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

Date: Sun, 20 May 2001 16:57:53 GMT
From: kpreid@attglobal.net (Kevin Reid)
Subject: Re: garbage collection in perl
Message-Id: <1etmdvk.s7krfqkq8lgoN%kpreid@attglobal.net>

M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:

> >But b has a loophole: one can circumvent the runtime-effect, and leave
> >only the compile-time effect (creation of a "name") of my():
> >
> >  my $var if 0;
> 
> But note that's a bug.   It might even get mended some day.
> (The only reason it hasn't been mended already is that nobody knows
> how to fix it without adding overhead in the much more common case
> 
>    my $var = 'some_initial_value';

I know almost nothing about Perl's internals, so please excuse me if
this suggestion is inapplicable,  but what if the run-time effect of
"my" is, at compile time, moved "before" any conditional that is not
also a scope? For example,

  my $var if 0;

becomes

  my $var;
  <nothing> if 0;

and

  my $var = split // if $_;

becomes

  my $var;
  $var = split // if $_;

and

  my $var = 'some_initial_value';

is unaffected because it doesn't contain a conditional.

-- 
 Kevin Reid: |    Macintosh:    | Me want Perl 6!
  "I'm me."  | Think different. | 


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

Date: Mon, 21 May 2001 08:22:29 +0200
From: Koos Pol <koos_pol@nl.compuware.com.NOJUNKMAIL>
Subject: Re: Hash: keys to variable names, or variable names to keys?
Message-Id: <9eae1a$nqk@news.nl.compuware.com>

Uri Guttman wrote:

> >>>>> "KP" == Koos Pol <koos_pol@nl.compuware.com.NOJUNKMAIL> writes:
> 
>   KP> How about something like:
>   KP> @list_of_checks (
>   KP>   {
>   KP>     criterium => '$lastnameLength > 30',
>   KP>     message   => "Your entry for last name is too long. ".
>   KP>                  "We allowed 30 characters, but your name took ".
>   KP>                  "$lastnameLength. Sorry, can you give us something
>   ".
>   KP>                  "shorter";
>   KP>   },
>   KP>   {
>   KP>     criterium => '$middleLength > 20' ,
>   KP>     message   => "Your middle name entry is too long. " .
>   KP>                  "We allowed 20 characters, but your input took " .
>   KP>                  "$middleLength. Sorry, can you find an alias or ".
>   KP>                  "abbreviate somehow?"
>   KP>   }
>   KP> )
>   KP> foreach $testrun (@list_of_checks) {
>   KP>    print $testrun->{message} if (eval $testrun->{criterium});
>   KP> }
> 
> gack! that eval is evil. way overkill for this. use some nested data
> structures as others have posted. use eval only when nothing else will
> do.
> 
> you can convert each criterium to a list of the name part and
> length. that can be indexed into the the data hash and the length
> checked. it is not that complex so don't be afraid of it.

Hmmm, I chose this construction as it relieves you of these conversions. If 
you only have "length($firstname) > 10)" kind of criteria, the nested data 
structures are by far the best option. Agreed.
But as soon as you divert from them, the %vars and %lengths don't work 
anymore. Suppose you introduce further criteria like length($firstname) 
must be <= length($lastname). 
The eval costruct allows me to do this on the fly. Otherwise I would need 
to figure additional programming logic.
Anyways, that was my motivation for the eval.

>   KP> I am positive this code does not run as written here. But I hope I
>   KP> demonstrated how you can keep the data and logic seperated.
> 
> no, you converted one problem for another. eval is not meant to solve
> the symbolic ref issue. use hashes and data structures instead.
> 
> uri

I am not really sure I understand what the problem is I introduced. Care to 
elaborate?

Cheers,

-- 
Koos Pol - Systems Administrator - Compuware Europe B.V. - Amsterdam
koos_pol@nl.compuware.com_NO_JUNK_MAIL



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

Date: Mon, 21 May 2001 13:01:28 +0100
From: "Matt L." <mlaw@talk21.comNOSPAM>
Subject: Inserting data at the beginning of a file?
Message-Id: <gm7O6.3919$26.32328@NewsReader>

Hi!
Another newbie question:
If you want to open a file and write data to the beginning of the file how
do you do it?
I have only seen examples of standard file write operations where the data
is appended to the existing file.


TIA,

Matt.




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

Date: 21 May 2001 13:02:16 +0100
From: nobull@mail.com
Subject: Re: Inserting data at the beginning of a file?
Message-Id: <u9lmnqc2yu.fsf@wcl-l.bham.ac.uk>

"Matt L." <mlaw@talk21.comNOSPAM> writes:

> Another newbie question:

The only reasonable interpretations I could think of would be "not
recently discussed here"[1] or "not answered in the FAQ"[2].

Neither of these apply in this case, so what, pray to _you_ mean by
"another"?  Perhaps you meant to say "The same old FAQ".

It is considered rude not to look in the group before you post.

It is considered rude not to check the FAQ before you post.

[1] 3 days ago: "Adding lines to the beginning of a data file?"

[2] FAQ: "How do I ... append to the beginning of a file?"
-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Mon, 21 May 2001 14:26:21 +0200
From: "Tom Klinger" <admin@the-piper.net>
Subject: Re: Inserting data at the beginning of a file?
Message-Id: <3b090a86@news.i-one.at>


"Matt L." <mlaw@talk21.comNOSPAM> wrote in message
news:gm7O6.3919$26.32328@NewsReader...
> Hi!
> Another newbie question:
> If you want to open a file and write data to the beginning of the file how
> do you do it?
> I have only seen examples of standard file write operations where the data
> is appended to the existing file.
>
Hi Matt,

for this case you can take a look into Perlfaq5 "Files and Formats",
available under
http://www.perl.com/pub/doc/manual/html/pod/perlfaq5.html#How_do_I_change_on
e_line_in_a_fi (maybe can have a newline after posting) or simply enter on
the command line perldoc -q begin.

hth, Tom




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

Date: Mon, 21 May 2001 14:00:39 +0100
From: "Matt L." <mlaw@talk21.comNOSPAM>
Subject: Re: Inserting data at the beginning of a file?
Message-Id: <Ld8O6.3930$26.33120@NewsReader>

Thanks Tom.




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

Date: Mon, 21 May 2001 11:05:34 +0200
From: "Tom Klinger" <admin@the-piper.net>
Subject: Need help on formatting output
Message-Id: <3b08db6f$1@news.i-one.at>

Hi!

I've a small problem with formatting the output.

Here's a code snippet from the program:

 .... # Read directories from specified directory and store to @storedirs
foreach(@storedirs) {
 if ( -d "$rootdir/$_" ) { # Is the name a directory then continue?
  .... # read content of that directory and store into @programs.
  open (PROGRAMS, ">>file.txt") || die "Cannot write to file: $!\n";
  select (PROGRAMS); # choose format template
  foreach my $program (@programs) {
    .... # preformatting the names and store to different variables
# I know that PROGRAMS could be located at the and but before I got
# a "Segmentation error" so I putted it here
format PROGRAMS_TOP =

Directoryname: @<<<<<<<<<<<<<<
$_

Programname                         Version  System
---------------------------------------------------
 .
format PROGRAMS =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<< @<<<<<<<
$name, $version,$system
 .
   write PROGRAMS;
  } # end foreach @programs
  close (PROGRAMS);
 } # end if loop

}# end foreach @storedirs
exit;

The output looks like this:

Directoryname: 20010520

Programname                         Version  System
---------------------------------------------------
Alibaba                             1.0      Linux
Startrek                            40.1     Mac
Zent                                4.04     Linux
AlphaCentauri                       8.2      Win
 ....

Looks nice at the first look. My problem at this is that i.e. AlphaCentauri
is already located in the next directory 20010521. But written in the
content output of 20010520.

How can I handle this that after the directory is finished a new page with
header is started?

For easier understanding the filesystem structure looks like this:

/home/user   <--- my root directory where I start
         /20010520  <-- page 1
              /Alibaba.v1.0.Linux
              /Startrek.v40.1.Mac
              /Zent.v4.04.Linux
         /20010521  <-- page 2
              /AlphaCentauri.v8.2.Win
              .
              .
         .
         .

Any help would be great. Looked already into several documentation
(Programming Perl, ....), but either I didn't catch the sense behind or I'm
a little bit stupid ....

Thanks in advance, Tom

P.S.: Excuse my maybe worse English, I'm still Austrian ... ;)




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

Date: Mon, 21 May 2001 04:43:27 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Need help with regexp and returned data.
Message-Id: <3B08D52F.12CFB5FC@earthlink.net>

Jason C. Hill wrote:
> 
> Here is the code:
> 
> my @sardata = <$sock>;
> 
> foreach $lines (@sardata) {
>        if ($lines =~ /atch/ .. /Average/) {
>                    print "$lines";
>       }
> }
> 
> Basically, we've opened a Socket to a port, grabbed some type of ASCII
> Data and put it all in an array "sardata"

Why?  Surely you can put a read on the socket in your loop control.

while( defined $_ = <$sock> )

Should work just as well.

[snip sample data]
> Basically, I want to search through this data, and ONLY grab the
> information from a unique id "atch" to the FIRST instance of Average
> after the unique id "atch".  With the thought in mind, that the next
> time through I'll want to do it again from freemem to the next
> instance of Average after freemem.

Do you want to test for being equal to "atch" or test for containing
"atch" ?

Here's an [untested] example which does what I think you want:

while( defined $line = <$sock> ) {
	chomp $line;
	if( $line eq 'atch' .. $line eq 'Average' ) {
		print "atch: $line\n";
	} elsif( $line eq 'freemem' .. $line eq 'Average' ) {
		print "freemem: $line\n";
	}
}

Another version [also untested] is this, which might be more readable:

while( defined $_ = <$sock> ) {
	chomp;
	if( /^atch$/ .. /^Average$/ ) {
		print "atch: $_\n";
	} elsif( /^freemem$/ .. /^Average$/ ) {
		print "freemem: $_\n";
	}
}

Note that the regular expressions I use are anchored.

Here's a third.

my ($a, $f, $A) = ( qr/^atch$/, qr/^freemem$/, qr/^Average$/ );
1 while( defined($_ = <$sock>) && /$a/ );
print while( defined($_ = <$sock>) && /$A/ );
1 while( defined($_ = <$sock>) && /$f/ );
print while( defined($_ = <$sock>) && /$A/ );

-- 
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."


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

Date: Mon, 21 May 2001 14:22:51 +0200
From: harry macdonald <hmacdonald@europarl.eu.int>
Subject: Newbie perl CGI question
Message-Id: <3B09089A.291E9D39@europarl.eu.int>

Hello all,
   Please correct me if I'm wrong :-

    I'm trying to port from IIS to Apache (still on NT).
    And Apache doesn't seem to like Javascript.

So how can I do the following in Perl :-
     print"<SCRIPT LANGUAGE=JavaScript>
     var person_selected = \"../index.htm\";
     top.location.href= person_selected;
     </script>n\n";

Thanks in advance
Harry



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

Date: Mon, 21 May 2001 18:09:20 +0530
From: "Rajesh Gupta" <rajesh_gupta@mailcity.com>
Subject: newbie Question PERL
Message-Id: <9eb26m$5ub$1@newshost.mot.com>

Hi,

 I downloaded a perl script and was trying to run it. The script is
something like

#!/usr/pds/bin/perl5.00404
use lib 'lib/';
use integer;
use DB_File;

I get an error message

Can't locate DBFile.pm

What could be the problem?? What shall I do to solve it ??

 Thanks
Rajesh Gupta




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

Date: Mon, 21 May 2001 10:13:01 +0200
From: "Christian Lutz" <lutz@imas-international.com>
Subject: password protection!
Message-Id: <O04O6.38$ba4.2048@nreader1.kpnqwest.net>

Hello NG!

I need a perl-script, that gives my web-site a password protection.

It should work without .htaccess and .htpasswd and Database like SQL.

Does anybody know one, where can I find some scripts???

cu
chris




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

Date: Mon, 21 May 2001 08:27:20 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl icon in Windows- reminder please
Message-Id: <v3khgtc32io17k5emnvmjkhgrn71v7du7d@4ax.com>

David Soming wrote:

>I have perl version 5.005_03 built for MSWin32-x86-object. (On Win'98)
>
>The extension ".pl" displays an icon on my machine which prevents edit using
>notepad.
>Anyone remind me how to change this so I can use notepad... I forgot how to
>do it!

If you rightclick, isn't there a menu item "edit"?

If not, add the option yourself. Go to Settings -> Folder Options ->
File Types -> "Perl File" -> Edit -> New (action)

For "Action", enter "&Edit"; for "Application used...", browse to the
editor of your choice.

Close all, and you're done. You now have an Edit item in your rightclick
menu for your .pl files.

-- 
	Bart.


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

Date: Mon, 21 May 2001 10:54:52 +0200
From: "Rene Scheibe" <Rene.Scheibe@gmx.net>
Subject: print function
Message-Id: <9eal2p$1qv6p$1@ID-65612.news.dfncis.de>

I have very long string-variables like:
$teststring=
"line1part1
 line1part2
 line2part1"
or something like that.

When I print this variable perl prints all
in different lines but I want line1part1 and
line1part2 in one line and line2part1 in another.
Are there any parameters for print or printf that
say this function to ignore the normal linefeeds
in a string-variable definition so I just use \n for
linefeed.
Do you know what I mean?

Th@nx...




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

Date: Mon, 21 May 2001 09:14:56 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: print function
Message-Id: <fumhgts8f7taf9di0be20l0m3d0sbmv0km@4ax.com>

Rene Scheibe wrote:

>I have very long string-variables like:
>$teststring=
>"line1part1
> line1part2
> line2part1"
>or something like that.
>
>When I print this variable perl prints all
>in different lines but I want line1part1 and
>line1part2 in one line and line2part1 in another.
>Are there any parameters for print or printf that
>say this function to ignore the normal linefeeds
>in a string-variable definition so I just use \n for
>linefeed.

Can't be done. The reason is simple: when compiling, Perl turns "\n"
into  the character it represents (chr(10) on PC and Unix, chr(13) on
Mac). So at runtime, there's no distinction to make any more.

Possible solutions:
 * don't wrap your text
 * do this:

$teststring=
"line1part1".
"line1part2
line2part1";

* use your own encoding, and procoess it yourself, using regexes. Not
for the faint of heart.

A backslash just before the end of a line in a doublequotish string
won't do any good, because Perl will have removed it already at the time
you get to process it.

$_ = "part 1 \
part 2";
print;

This doesn't print any backslash.

-- 
	Bart.


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

Date: Mon, 21 May 2001 09:28:17 +0100
From: "Matt L." <mlaw@talk21.comNOSPAM>
Subject: Re: Problems password protecting CGI Script
Message-Id: <pe4O6.2439$0g4.31321@NewsReader>

It is real code and I think you missed the bit about 'Newbie'...




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

Date: Mon, 21 May 2001 10:10:19 +0100
From: "Matt L." <mlaw@talk21.comNOSPAM>
Subject: Re: Problems password protecting CGI Script
Message-Id: <PR4O6.2085$26.29793@NewsReader>

> Change that '||' to 'or'. To see what Perl thinks you want, try this:
>
> [gwyn@thislove:~]$ perl -MO=Deparse,-p
> not $username eq 'User' || not $pw eq 'PW'
> __END__

The Web host for these pages does not allow HTTP authentication for any CGI
scripts (specifically anything in '/CGI-LOCAL').  So I thought (Remeber I'm
new to CGI...) that I'd create a normal HTML login page to submit the
username and password to a CGI script for validation.  I realise that this
requires the login info be present in every page to validate against, but I
didn't see that as a major problem.  I then assumed that by copying this
info into hidden form fields it would be available to subsequent pages.
This is not ideal since the hidden form fields are easily viewable in the
document source, but I couldn't think of a better way.
The script that I am trying to protect allows a user to upload an image to
the server - I'm trying to let them keep their content up to date easily.
Ultimately it will also read and write to a file which provides the text for
the .shtml page in question, thus keeping the textual info up to date too.
Obviously this is open to exploitation by malicious users, hence the need
for authentictaion of some sort.

Please feel free to correct me or maybe there is a better way?

Many thanks for your help.

Matt.




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

Date: Mon, 21 May 2001 10:13:06 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Problems password protecting CGI Script
Message-Id: <slrn9ghqhc.l38.tjla@thislove.dyndns.org>

"Mein Lufkissenfahrzeug ist voller Aale"
said Matt L. (mlaw@talk21.comNOSPAM) in 
<PR4O6.2085$26.29793@NewsReader>:

>The Web host for these pages does not allow HTTP authentication for any CGI

Here is where the question slips out of the realms of known space (ie.
Perl) and into the Twilight Zone (ie. CGI). I suggest you ask this
question again in another group, possibly
comp.infosystems.www.authoring.cgi.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
We know what we are, but know not what we may be.
		-- William Shakespeare, "Hamlet - Act IV Scene V"


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

Date: Mon, 21 May 2001 05:41:08 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: System Call within Daemon - TAKE 2
Message-Id: <3B08E2B4.177999F7@earthlink.net>

Michael Vera wrote:
> 
> Thanks, good answer. Now, here is some code:
> 
>     print $new_sock "Starting dm_oracle\n";
>     open(SYS, "$bin_path/start_dm_oracle |" );
>     SYS->autoflush(1);
>     while(<SYS>) {
>       chomp($_);
>       print $new_sock "$_<br>\n";
>     }
>     sleep 5;
>     print $new_sock " done.<br>\n";
>     close(SYS);me code:

First off, I don't think this works.  What type of object is SYS?  What
makes you think that you can treat it as an object and call methods on
it?

Also, I don't see why you would *want* to use fork/exec at all, here.

print $new_sock "Starting dm_oracle<br>\n";
print $new_sock join "<br>\n", qx{$bin_path/start_dm_oracle};
print $new_sock "<br>done.<br>\n";

qx is backticks.  Calling it in list context splits it on /$/.  There's
no need to remove trailing newlines, due to how they will be treated by
the web browser.  There *is* a need to insert <br> between lines, but we
don't have to do it by hand in a for loop; a join works fine.

The only reason which we might not want to slurp the program's output
like this is if it takes a long time outputing, and want to send the
data to the user asap.  In that case, you *still* don't need fork/exec.

print $new_sock "Starting dm_oracle<br>\n";
open my $ora, "$bin_path/start_dm_oracle|" or die $!;
print $new_sock $_,"<br>\n" while( defined $_ = <$ora> );
close $ora or die $!;
print $new_sock "done.<br>\n";

Opening to/from a pipe usually does it with a call to popen, which in
turn calls fork and exec.  Remember that you should ALWAYS test the
return value of open() or close().  For this situation, open() will only
fail if it can't fork; there is no error reported here if exec() fails.
To find out whether the exec() failed or succeeded, you need to do a
test on the close() call.  The simple "die $!" I used following the
close really gives *much* too little information; you should have a
special function for testing $? (aka $CHILD_ERROR).

> What I want to do is capture output from the system call, dm_oracle,
> to print to the socket.

Ok, that's doable.

> But the system call gains control of my socket
> after the parent closes.

No it doesn't.  Where did you get that strange idea from?
Neither fork nor exec will give control of your socket to dm_oracle.

> If I fork() and exec(), I don't think I will gather any output from
> the system call.

System, and backticks, and open to/from a pipe, all do any fork/exec
which you might need.  Doing them yourself does not help with the
example you gave.

> If you dont feel that this is perl related, please tell me where I can
> post fork() and exec() questions.

If you want to ask what perl does special wrt fork and exec, this is the
place to ask.  If you want to ask about fork and exec in general, then
you probably want a unix group.

The real problem, I think, is that you don't seem to know what you want.

-- 
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."


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

Date: Mon, 21 May 2001 07:16:38 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: time of a file
Message-Id: <slrn9ghfl2.m8i.bernard.el-hagin@gdndev25.lido-tech>

On Mon, 21 May 2001 08:58:50 +0200, Rene Scheibe <Rene.Scheibe@gmx.net> wrote:
>How do I get the date, time and so on of a file?

perldoc -f stat

Cheers,
Bernard


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

Date: 21 May 2001 04:40:07 -0700
From: mwilliams@uk.ibm.com (Matt Williams)
Subject: Re: time of a file
Message-Id: <5f5140d2.0105210340.5c09087e@posting.google.com>

"Rene Scheibe" <Rene.Scheibe@gmx.net> wrote in message news:<9eae97$1q5ma$1@ID-65612.news.dfncis.de>...
> How do I get the date, time and so on of a file?#

#!/usr/bin/perl -w

($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$bloks)
= stat($filename);

goto "perldoc -f stat" for more info.


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

Date: Mon, 21 May 2001 12:00:46 +0200
From: Ellison Bone <ellison@holzerath.de>
Subject: Re: Urgent: CGI program wanted
Message-Id: <3B08E74E.59209462@holzerath.de>

> [...]
> Anyone here have or know of a perl script which does (or modification) the
> following...

No problem. What's your budget?
(You do not expect others to do your job, right?

>
> [...]I have been looking around for ages now

Really?

> --
> NO NONSENSE professional Websites:
> www.your-new-site.com

This site is not professional at all.

Regards
Ellison



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

Date: Mon, 21 May 2001 08:47:37 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why can't I localize a lexical variable?
Message-Id: <kglhgtsks2ir6oh4b1ttqlqr4q3m5lnnji@4ax.com>

Godzilla! wrote:

>I posted an article within the past couple of weeks on
>how a rogue programmer, such as myself, would bend a rule
>to accomplish this.
>
>
>#!perl -w
>
>my ($variable) = "Godzilla Rocks";
>
>print $variable;
>
>&Rock;
>
>sub Rock
> {
>  my ($variable) = " N Rolls! ";
>  print $variable;
> }
>
>print "$variable!";

It's not the same thing. It's the feature that apparently gives Clinton
A. Pierce a headache, which is what I am after. I *want* dynamic
scoping, but limited by a variable's lexical scope as well.

-- 
	Bart.


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

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


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