[29487] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 731 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 8 21:09:48 2007

Date: Wed, 8 Aug 2007 18:09:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 8 Aug 2007     Volume: 11 Number: 731

Today's topics:
    Re: [Semi-OT] Configuring emacs (was Re: Subroutines an <yankeeinexile@gmail.com>
    Re: [Semi-OT] Configuring emacs (was Re: Subroutines an <m@rtij.nl.invlalid>
    Re: How to parse directory structure from FTP LIST  usenet@DavidFilmer.com
        how to tranpose a huge text file <jiehuang001@gmail.com>
    Re: how to tranpose a huge text file <wahab@chemie.uni-halle.de>
    Re: how to tranpose a huge text file <jgibson@mail.arc.nasa.gov>
    Re: how to tranpose a huge text file xhoster@gmail.com
    Re: I need to display pdf. <ashishrai@gmail.com>
    Re: List of all modules installed on a system <tadmc@seesig.invalid>
    Re: Matching problem <tadmc@seesig.invalid>
        perl to parse out iostat information on solaris 9 <inetquestion@hotmail.com>
    Re: perl to parse out iostat information on solaris 9 <tadmc@seesig.invalid>
        Question on grep and reading from file <pinaki_m77@yahoo.com>
    Re: Question on grep and reading from file <wahab@chemie.uni-halle.de>
    Re: Question on grep and reading from file <yankeeinexile@gmail.com>
    Re: Question on grep and reading from file xhoster@gmail.com
    Re: Replacing a line <tadmc@seesig.invalid>
    Re: Subroutines and '&' anno4000@radom.zrz.tu-berlin.de
    Re: Subroutines and '&' <emschwar@pobox.com>
    Re: Subroutines and '&' <mritty@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 08 Aug 2007 13:17:21 -0500
From: Lawrence Statton <yankeeinexile@gmail.com>
Subject: Re: [Semi-OT] Configuring emacs (was Re: Subroutines and '&')
Message-Id: <873aythowe.fsf@hummer.cluon.com>

In your .emacs file

(defalias 'perl-mode 'cperl-mode)

-- 
	Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
place them into the correct order.


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

Date: Wed, 8 Aug 2007 23:14:14 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: [Semi-OT] Configuring emacs (was Re: Subroutines and '&')
Message-Id: <pan.2007.08.08.21.14.13@rtij.nl.invlalid>

On Wed, 08 Aug 2007 13:17:21 -0500, Lawrence Statton wrote:

> In your .emacs file
> 
> (defalias 'perl-mode 'cperl-mode)

Snarfed. Thanks!

M4


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

Date: Wed, 08 Aug 2007 19:45:18 -0000
From:  usenet@DavidFilmer.com
Subject: Re: How to parse directory structure from FTP LIST
Message-Id: <1186602318.471059.67020@x40g2000prg.googlegroups.com>

On Aug 8, 11:08 am, lg <l...@invalid.com> wrote:

> First of all is the directory list standard? Does file/directory name start at
> column 56 etc?

> If not how do FTP programs parse info if it's not standardised?

FTP output (and even commands) differ widely between systems.  For
example, on my system (AIX), LIST is not even a valid FTP command.  In
AIX, if you do 'DIR' then you get a long listing (like you get with
LIST), but if you do 'ls' then you get a list of only the filenames.
Maybe your FTP program also has a command to list only the filenames.

But if you want to really assure that the system is as bullet-proof as
possible then you should use an FTP module such as Net::FTP instead of
relying on the result of system commands.  With a module you always
know what to expect, and it is not affected by the vagaries of your
particular ftp program (and it won't break if your ftp program is
changed or upgraded and the output changes).


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



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

Date: Wed, 08 Aug 2007 20:56:24 -0000
From:  Jie <jiehuang001@gmail.com>
Subject: how to tranpose a huge text file
Message-Id: <1186606584.143555.119720@k79g2000hse.googlegroups.com>


I have a huge text file with 1000 columns and about 1 million rows,
and I need to transpose this text file so that row become column and
column become row. (in case you are curious, this is a genotype file).

Can someone recommend me an easy and efficient way to transpose such a
large dataset, hopefully with Perl ?

Thank you very much!

Jie



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

Date: Wed, 08 Aug 2007 23:09:05 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: how to tranpose a huge text file
Message-Id: <f9dbdh$1mvm$1@nserver.hrz.tu-freiberg.de>

Jie wrote:
> I have a huge text file with 1000 columns and about 1 million rows,
> and I need to transpose this text file so that row become column and
> column become row. (in case you are curious, this is a genotype file).
> 
> Can someone recommend me an easy and efficient way to transpose such a
> large dataset, hopefully with Perl ?

Is this a fixed format? Has each row exactly the same number of columns?
Does each row have a "line ending" character?

How's that beast looking? Normally, you'd read it in one stroke
(1,000c x 10^6r ==> 1Gig) and dump out the new rows via substr()
offsets (R times rowlength + C) subsequentially.

But without having more info, I could only guess ...

Regards

M.


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

Date: Wed, 08 Aug 2007 16:53:35 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: how to tranpose a huge text file
Message-Id: <080820071653359711%jgibson@mail.arc.nasa.gov>

In article <1186606584.143555.119720@k79g2000hse.googlegroups.com>, Jie
<jiehuang001@gmail.com> wrote:

> I have a huge text file with 1000 columns and about 1 million rows,
> and I need to transpose this text file so that row become column and
> column become row. (in case you are curious, this is a genotype file).
> 
> Can someone recommend me an easy and efficient way to transpose such a
> large dataset, hopefully with Perl ?

So you want a file with 1000 rows and 1 million columns? Ouch!

First thing to try is to attempt to read the entire file into memory at
once. Then, as Mirco suggested, use substr to extract columns from each
row.

How big are your fields? Just one character? 

If you can't read the whole file in at once, you can consider other
options:

1. If the rows are all the same length, you can use seek() to move
around in the file and read all the data from each column in every row.
It's going to be slow, though. (perldoc -f seek)

2. You can write out each field with its column number and row number
prepended to another file, e.g. "col:row:data\n". Then sort that file
by column number and row number using an external sort. However, your
temporary file is going to be very big. Unix sort can handle very large
files, though.

3. You might consider putting your data into a database and making the
appropriate queries.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: 09 Aug 2007 00:19:38 GMT
From: xhoster@gmail.com
Subject: Re: how to tranpose a huge text file
Message-Id: <20070808201941.354$WG@newsreader.com>

Jie <jiehuang001@gmail.com> wrote:
> I have a huge text file with 1000 columns and about 1 million rows,
> and I need to transpose this text file so that row become column and
> column become row. (in case you are curious, this is a genotype file).
>
> Can someone recommend me an easy and efficient way to transpose such a
> large dataset, hopefully with Perl ?

Before doing that, I would spend a few minutes considering whether the time
would be better spent in making a more permanent solution, perhaps by
structuring the data so you can jump through it at will using seek or
sysseek, rather than always scanning it.

Anyway, I'd do something combining Perl and the system sort command
something like this:

perl -lne '@x=split/\t/; foreach (0..$#x) {
           print "$_\t$.\t$x[$_]\n"}}' big_file.in | \
  sort -k1n -k2n | \
  perl -ne 'chomp; @x=split/\t/,$_,3; print $x[2];
            print $.%1000 ?"\t":"\n"' > big_file.out



Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Wed, 08 Aug 2007 18:40:19 -0000
From:  Ash <ashishrai@gmail.com>
Subject: Re: I need to display pdf.
Message-Id: <1186598419.749686.126490@22g2000hsm.googlegroups.com>

I found this module Wx::ActiveX::Acrobat. Hopefully it solves my
problem. Thanks.


On Aug 8, 1:56 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> Ash <ashish...@gmail.com> wrote in news:1186592628.096967.150000
> @d55g2000hsg.googlegroups.com:
>
> > Can I display pdf file in Perl GUI similar to using plug-in in IE or
> > Firefox?
> > I am using wxPerl for building GUI. Thanks a lot for any pointer.
>
> I have never tried it myself, but you could try embedding the Acrobat
> ActiveX object or looking for some other PDF rendering engine.
>
> I don't see what this has to do with Perl, though.
>
> Sinan
>
> --
> A. Sinan Unur <1...@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
> clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>




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

Date: Wed, 8 Aug 2007 19:51:10 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: List of all modules installed on a system
Message-Id: <slrnfbkp7u.3se.tadmc@tadmc30.sbcglobal.net>

["Followup-To:" header set to comp.lang.perl.misc.]
Ignoramus8011 <ignoramus8011@NOSPAM.8011.invalid> wrote:
> On Wed, 08 Aug 2007 17:53:44 GMT, A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
>> Ignoramus8011 <ignoramus8011@NOSPAM.8011.invalid> wrote in news:6_qdnV58mNmwnSfbnZ2dnUVZ_rTinZ2d@giganews.com:
>>
>>> Is there some clever, canonical way to find out out all modules that
>>> were installed on the system


>> Read the FFAQ:


> You have such a pleasant personality, 


Expecting pleasantness while asking a Frequently Asked Question
is an unrealistic expectation.


> you must be very good at getting
> along with people! 


And you, obviously, are not.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Wed, 8 Aug 2007 19:12:34 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Matching problem
Message-Id: <slrnfbkmvi.3se.tadmc@tadmc30.sbcglobal.net>

Aaron Sherman <AaronJSherman@gmail.com> wrote:
> On Aug 5, 6:32 pm, Tad McClellan <ta...@seesig.invalid> wrote:
>
>> See the "Quote and Quote-like Operators" section in:
>>
>>    perldoc perlop
>>
>> > Would /$data2\Q/ also work?
>>
>> What happened when you tried it?
>
> That seems sort of rude....


Teaching someone how to answer such a question without being
dependent on others is liberating, not rude.

Molly coddling them by reading the docs to them is doing
them a disservice. It encourages them to be enslaved to others.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Wed, 08 Aug 2007 16:53:48 -0700
From:  inetquestion <inetquestion@hotmail.com>
Subject: perl to parse out iostat information on solaris 9
Message-Id: <1186617228.630005.101380@q75g2000hsh.googlegroups.com>

For the program below why are all 4 attributes not getting filled in.
The data seems to be coming across per the Debug statement...

btw - I am running this on solaris 9.  The problem seems to be related
to the whitespace at the beginning of the line, but I thought the
regex should account for it...

-Inet

#!/usr/bin/perl

chomp($CPU=`iostat -c 1 2 | tail -1`);
($usrcpu,$syscpu,$wiocpu,$idlecpu) = split(/\s+/,$CPU);

print "DEBUG: $CPU\n";
print "usrcpu: $usrcpu\n";
print "syscpu: $syscpu\n";
print "wiocpu: $wiocpu\n";
print "idlecpu: $idlecpu\n";



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

Date: Wed, 8 Aug 2007 19:44:57 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: perl to parse out iostat information on solaris 9
Message-Id: <slrnfbkos9.3se.tadmc@tadmc30.sbcglobal.net>

inetquestion <inetquestion@hotmail.com> wrote:

> For the program below why are all 4 attributes not getting filled in.
> The data seems to be coming across per the Debug statement...


What is "the Debug statement"?


> btw - I am running this on solaris 9.  


If you show what the data looks like, then even people who are not
on Solaris could attempt to help you.

I have no idea what the output of iostat looks like.


> The problem seems to be related
> to the whitespace at the beginning of the line, 


Then one solution would be to remove the whitespace at the beginning 
of the line before split()ting the string.

   $CPU =~ s/^\s+//;


> but I thought the
> regex should account for it...


The 2nd sentence of the documentation for the function you are using says:

   By default, empty leading fields are preserved

You have an empty leading field.


> ($usrcpu,$syscpu,$wiocpu,$idlecpu) = split(/\s+/,$CPU);


Another solution would be to discard the empty leading field:

    (undef, $usrcpu, $syscpu, $wiocpu, $idlecpu) = split(/\s+/, $CPU);


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Wed, 08 Aug 2007 21:11:06 -0000
From:  googler <pinaki_m77@yahoo.com>
Subject: Question on grep and reading from file
Message-Id: <1186607466.324073.253890@m37g2000prh.googlegroups.com>

Inside my Perl script, I had to check if a particular pattern appears
in a certain file or not (only a yes/no answer). I did it as below:
      @matching_lines = grep { /$srchpat/ } <MYFILE>;
      print "Pattern found\n" if ($#matching_lines != -1);

I was wondering if there is a more efficient way to do this. Is it
possible to use the Unix "grep" command to do this inside my script?
If so, how? Will that be more efficient (faster)?

I have another question. Is there a way to read a particular line in a
file when I know the line number (without using a loop and reading
each line at a time)? I guess the below code would work.
@lines = <MYFILE>;
$myline = $lines[$linenum-1];
But this will read the entire file into the array @lines and can take
up a lot of memory if the file is huge. Is there a more efficient
solution?

Thanks.



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

Date: Wed, 08 Aug 2007 23:25:28 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Question on grep and reading from file
Message-Id: <f9dcc7$1n9c$1@nserver.hrz.tu-freiberg.de>

googler wrote:
> Inside my Perl script, I had to check if a particular pattern appears
> in a certain file or not (only a yes/no answer). I did it as below:
>       @matching_lines = grep { /$srchpat/ } <MYFILE>;
>       print "Pattern found\n" if ($#matching_lines != -1);
> 
> I was wondering if there is a more efficient way to do this. Is it
> possible to use the Unix "grep" command to do this inside my script?
> If so, how? Will that be more efficient (faster)?

In almost all cases, a sequential approach will be *much*
faster on *large* files (>= 100MB), like

    <pseudo>
    ...
    my @matching_lines;
    while( <MYFILE> ) {
       push @matching_lines, $_
          if /$srchpat/
    }
    print "Pattern found\n"
       if scalar @matching_lines;
    ...

> I have another question. Is there a way to read a particular line in a
> file when I know the line number (without using a loop and reading
> each line at a time)? I guess the below code would work.
> @lines = <MYFILE>;
> $myline = $lines[$linenum-1];
> But this will read the entire file into the array @lines and can take
> up a lot of memory if the file is huge. Is there a more efficient
> solution?

No, not really. Besides the 'tie' approach (which is sometimes
too slow), you can always read large files fast 'record by record'
(eg. lines) and check the line no via "$." ...

Regards

M.


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

Date: 08 Aug 2007 16:35:28 -0500
From: Lawrence Statton <yankeeinexile@gmail.com>
Subject: Re: Question on grep and reading from file
Message-Id: <87y7glg15r.fsf@hummer.cluon.com>

googler <pinaki_m77@yahoo.com> writes:
> Inside my Perl script, I had to check if a particular pattern appears
> in a certain file or not (only a yes/no answer). I did it as below:
>       @matching_lines = grep { /$srchpat/ } <MYFILE>;
>       print "Pattern found\n" if ($#matching_lines != -1);
> 
> I was wondering if there is a more efficient way to do this. 

Yes, don't look at every line in the file -- stop looking as soon as
you've found any line that matches.

#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw/first/; # part of CORE in modern perls.

open my $myfile, '<', 'myfile' or die "Could not open `myfile' $!";

my $srchpat = qr/larkvomit/i;

print "Pattern found" if first { m/$srchpat/ } <$myfile>;

> Is it
> possible to use the Unix "grep" command to do this inside my script?
> If so, how? Will that be more efficient (faster)?

Could be, depending on a lot of variables -- the overhead of forking
and execing a grep process could easily swamp the gains of a machine
language grep vs. a perl loop.

> 
> I have another question. Is there a way to read a particular line in a
> file when I know the line number (without using a loop and reading
> each line at a time)? 

Not unless every line is exactly the same size.  There are techniques
to hide the read line-by-line and counting behind a curtain, but it
has to happen.

I guess the below code would work.
> @lines = <MYFILE>;
> $myline = $lines[$linenum-1];
> But this will read the entire file into the array @lines and can take
> up a lot of memory if the file is huge. Is there a more efficient
> solution?
> 
> Thanks.
> 

my $myline;
while ( my $line = <$myfile> ) { 
   if ($. == $linenum) { 
     $myline = $line;
     last;
  }
}

At least this way you don't have to read PAST the line you're
intersted in.  

-- 
	Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
place them into the correct order.


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

Date: 08 Aug 2007 23:40:44 GMT
From: xhoster@gmail.com
Subject: Re: Question on grep and reading from file
Message-Id: <20070808194047.016$IP@newsreader.com>

googler <pinaki_m77@yahoo.com> wrote:
> Inside my Perl script, I had to check if a particular pattern appears
> in a certain file or not (only a yes/no answer). I did it as below:
>       @matching_lines = grep { /$srchpat/ } <MYFILE>;

This reads the entire file, even if the match is in the first line.
(Potentially worse, it reads the entire into memory at once, as perl
is currently implemented.)

>       print "Pattern found\n" if ($#matching_lines != -1);
>
> I was wondering if there is a more efficient way to do this. Is it
> possible to use the Unix "grep" command to do this inside my script?

Sure.  There are many ways.  The simplest, if $srchpat and $filename don't
require protecting from shell interpretation, and $srchpat either doesn't
have special characters or only has ones that mean the same thing between
Perl and grep, would be something like this:

my $result=`grep -l $srchpat $filename`;

> If so, how? Will that be more efficient (faster)?

It would have more overhead, but will probably run faster once it gets
running (provided $srchpat is fairly simple)

> I have another question. Is there a way to read a particular line in a
> file when I know the line number (without using a loop and reading
> each line at a time)? I guess the below code would work.
> @lines = <MYFILE>;
> $myline = $lines[$linenum-1];
> But this will read the entire file into the array @lines and can take
> up a lot of memory if the file is huge. Is there a more efficient
> solution?

Unless you know how long each line is, or have otherwise pre-computed some
kind of index into the file, you need to read the entire file at least up
to the desired line and count newlines, either implicitly or explicitly.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Wed, 8 Aug 2007 19:38:16 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Replacing a line
Message-Id: <slrnfbkofo.3se.tadmc@tadmc30.sbcglobal.net>

Ved <vedpsingh@gmail.com> wrote:

[ Please learn to compose followups properly.
  Quoting 100 lines to add 2 lines will make you go invisible...
]


> Why is it not entering in this condition ?
>
>  if( m{^//#define \$module_nameFileLoadInput 1$} )


Probably because the string in $_ does not contain a '$' followed
by an 'm' followed by an 'o' followed by a 'd'...




You should attempt to write a short and complete program that we
can run that illustrates your problem.

Have you seen the Posting Guidelines that are posted here frequently?


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

$_ = '//#define BBPRxChanRouteFileLoadInput 1';
my $module_name = 'BBPRxChanRoute';
if( m{^//#define ${module_name}FileLoadInput 1$} )
    { print "true\n" }
else
    { print "false\n" }
 ------------------------------


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: 8 Aug 2007 18:48:46 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Subroutines and '&'
Message-Id: <5huhgeF3mnot7U1@mid.dfncis.de>

Lawrence Statton  <yankeeinexile@gmail.com> wrote in comp.lang.perl.misc:
> merlyn@stonehenge.com (Randal L. Schwartz) writes:
> > That's a flaw with perl-mode.  cperl-mode is far better, and actively
> > maintained.  First thing I do with an empty .emacs file is teach it
> > to replace perl mode with cperl-mode. :)
> > 
> 
> I agree with the solution to that *particular* problem, but as is oft
> said: Nothing but perl can parse Perl with absolute certainty.  While
> cperl-mode does not get nearly as confused nearly as often as
> perl-mode did, I have succeeded in confusing its parser on occasion.
> 
> That being said, what superior alternative does the grandparent poster
> propose?  Merely saying that the syntax-highlighter is imperfect does
> not obviate the benefits that even a mediocre highlighter offers.

Superiority is relative.  For the moment I'm still using the highlighter
that comes with vim though I find some of its properties annoying.  The
most significant problem is, as mentioned, the alternative of either
looking at mis-highlighted code or using a style I wouldn't use if
it weren't to appease the highlighter.  More generally, I'm not too
fond of the fruit-salad-like appearance of highlighted code in general.
Most of the time I'm just ignoring the colors (and underlines, and
italics, and what have you).

I guess I'll switch to no syntax highlighting per default and enabling
it from case to case when I think it would help, with some key bindings
thrown in to switch quickly.  It's a way to use a tool without it getting
in the way, or so I hope.

Anno


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

Date: 08 Aug 2007 13:16:11 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Subroutines and '&'
Message-Id: <87ps1x6dms.fsf@pobox.com>

merlyn@stonehenge.com (Randal L. Schwartz) writes:
> >>>>> "~greg" == ~greg  <g_m@remove-comcast.net> writes:
> 
> ~greg> It is still required,
> ~greg> but only when dealing with references (I think)
> 
> Or when dealing with a subroutine that is the same name as a built-in.
> See my other post.

That falls under my "But Doctor, it hurts when I do that" rule.
Naming your subs with the same name as a built-in is a bad idea, and I
don't mind in the slightest that perl warns you about it (you *did*
enable warnings, didn't you?).

-=Eric


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

Date: Wed, 08 Aug 2007 13:01:50 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Subroutines and '&'
Message-Id: <1186603310.227008.214550@d55g2000hsg.googlegroups.com>

On Aug 8, 1:59 pm, tru...@gmail.com wrote:
> On Aug 8, 6:39 am, Paul Lalli <mri...@gmail.com> wrote:
> > On Aug 8, 5:05 am, tru...@gmail.com wrote:
> > > my $MODE=param('Mode');
> > > {
> > >         no strict;
> > >         $MODE="GetLogin" unless $MODE; # default sub to execute
> > >         &$MODE; # else execute this sub
>
> > > }
>
> > You have no way of
> > knowing what that parameter is.  You are making the assumption
> > that the only way to contact your CGI script is via your
> > form.  This is incorrect.  A user can contact your CGI script
> > without ever going near your form.
>
> > You are allowing your users to call any subroutine in your
> > program.

> I see where that would be possible. But would a user not need
> to know the name of a subroutine in my script?

Yes he would.  But how difficult is that?  How difficult is it to just
*guess* for starters, but more specifically, your form's parameter
list is giving him at least a subset of all options.

> My goal is to try and combine as many functions as possible into
> one script, rather than have 5 or 6 separate scripts to maintain.

I have no idea what this issue has to do with the issue being
discussed.

> Which brings up a question: if a user
> can call any subroutine in my script, what's to stop them from
> running a separate script as well?

 ... absolutely nothing.  You should write ALL scripts residing on a
publically accessable webserver to be secure, and to check that only
those who are running the script "correctly" can do anything.  If I
randomly type the address to one of your CGI scripts into my browser's
address bar, passing it data of my own creation, your script should be
able to handle that gracefully and not do anything it shouldn't do.

> If there is no secure way to do this with this particular method I
> would like to know so as to fix it.

You've already been given (or considered yourself) a few ways to do
this correctly.  Either create a dispatch table as Anno demonstrated,
or check the value of each parameter to make sure it matches an
acceptable value.

Paul Lalli



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

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 V11 Issue 731
**************************************


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