[22363] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4584 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 19 09:05:44 2003

Date: Wed, 19 Feb 2003 06:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 19 Feb 2003     Volume: 10 Number: 4584

Today's topics:
        Bidir Array <branco@markdata.pt>
    Re: Clearing an array (Anno Siegel)
    Re: Clearing an array <ubl@schaffhausen.de>
    Re: Clearing an array <jurgenex@hotmail.com>
    Re: Extracting patterns (Gunnar Hjalmarsson)
        Input file format <j.j.konkle-parker@larc.nasa.gov>
        Memory usage/cleanup & hashes <jaeggi@embl-heidelberg.de>
    Re: Need Help with Pattern Matching <PleaseDontThrowSpam@Me.com>
    Re: Need Help with Pattern Matching <PleaseDontThrowSpam@Me.com>
        Redhat UTF the nightmare continues <go@way.com>
    Re: Redhat UTF the nightmare continues <minter@lunenburg.org>
    Re: Redhat UTF the nightmare continues <go@way.com>
    Re: Returning the field list from DBI (Anno Siegel)
    Re: Returning the field list from DBI <peakpeek@purethought.com>
    Re: Unsuccesful "Print" <PleaseDontThrowSpam@Me.com>
    Re: Uploading a file <REMOVEsdnCAPS@comcast.net>
    Re: Uploading a file <rereidy@indra.com>
    Re: use DBI; (Anno Siegel)
    Re: use DBI; <tassilo.parseval@post.rwth-aachen.de>
        wanted: BZIP2 module for Win32 and Linux <Ed+nospam@ewildgoose.demon.co.uk@>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 19 Feb 2003 14:03:22 +0000
From: Nuno Branco <branco@markdata.pt>
Subject: Bidir Array
Message-Id: <K8M4a.3441$MA.1851453@newsserver.ip.pt>


I am trying to make a bidirectional array, been spending some time at google
and perldoc.com and I'm surprised I didn't found what I am looking for.

Basically what I want is to have something like @array[1][5] and access
this, but I cannot find a way to do it.

Can someone help me with some code or redirect me to nice documentation?

Thank you

-- 
Best Regards,
Nuno Branco




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

Date: 19 Feb 2003 11:14:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Clearing an array
Message-Id: <b2vous$o03$2@mamenchi.zrz.TU-Berlin.DE>

Jason Singleton <jsn@microlib.demon.co.uk> wrote in comp.lang.perl.misc:
> According to the perl documentaion you clear an array by using one of
> the following
> 
>     @whatever = ();
>     $#whatever = -1; 
> 
> But this dosn't work it dosn't do anything, ...

How did you arrive at this conclusion?  (It works as advertised.)
What code did you run to show that the array isn't cleared?  Show
it, and someone will certainly be able to explain what is wrong.

Anno


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

Date: Wed, 19 Feb 2003 12:42:57 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Clearing an array
Message-Id: <b2vtr7$4j9$1@news.dtag.de>

Jason Singleton wrote:
> According to the perl documentaion you clear an array by using one of
> the following
> 
>     @whatever = ();
>     $#whatever = -1; 
> 
> But this dosn't work it dosn't do anything, I have got it to work with
> 
>     %whatever=();
> 
> I store entries in the array like $whatever{'STUFF'}="data"; am I
> misunderstanding somthing here?

use strict;   # and
use warnings;


and look up the distinction between array and hashes (sometimes called 
assoziative arrays).

->malte



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

Date: Wed, 19 Feb 2003 13:48:15 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Clearing an array
Message-Id: <zWL4a.12414$_k4.10384@nwrddc03.gnilink.net>

Jason Singleton wrote:
> According to the perl documentaion you clear an array by using one of
> the following
>
>     @whatever = ();
>     $#whatever = -1;
>
> But this dosn't work it dosn't do anything,

It sets the array to the empty list resp. it sets the length of the array to
0.
Both will effectivley empty the array (I guess that's what you mean with
"clear an array").

I have got it to work with
>
>     %whatever=();

No, that doesn't 'clear' an array, that 'clears' a hash.

> I store entries in the array like $whatever{'STUFF'}="data";

That would be a miracle because $whatever{'STUFF'}="data" stores the value
"data" in the hash %whatever. There is no array involved here.

> am I misunderstanding somthing here?

I think you are confusing arrays and hashes.

jue




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

Date: 19 Feb 2003 05:26:45 -0800
From: noreply@gunnar.cc (Gunnar Hjalmarsson)
Subject: Re: Extracting patterns
Message-Id: <3fcbff18.0302190526.6936cc0f@posting.google.com>

Ryan McCarthy <remccart@uiuc.edu.spam> wrote in message news:<vKz4a.37$o7.1175@vixen.cso.uiuc.edu>...
> I am trying to extract to an array all the different permutations of a 
> string formatted like this:
> 
> ABCD(E|F)GHI...
> 
> Where this would produce an array with two entries
> 
> 1. ABCDEGHI
> 2. ABCDFGHI

Before I saw Benjamin's sophisticated solution, I put together this code:

    $string = 'ABC(1|2)DEF(3|4)GHI';
    push @array, $string;
    for (1..$string =~ s/(\(\w\|\w\))/$1/g) {
        # for each occurrence of (X|Y)
        for (@array) {
            ($string = $_) =~ s/\((\w)\|\w\)/$1/;
            push @tmp, $string;
            ($string = $_) =~ s/\(\w\|(\w)\)/$1/;
            push @tmp, $string;
        }
        @array = splice @tmp;
    }

It results in these entries in @array:

    ABC1DEF3GHI
    ABC1DEF4GHI
    ABC2DEF3GHI
    ABC2DEF4GHI

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Wed, 19 Feb 2003 08:54:08 -0500
From: Joel Konkle-Parker <j.j.konkle-parker@larc.nasa.gov>
Subject: Input file format
Message-Id: <3E538C80.3010602@larc.nasa.gov>

I need to create an input file format for my perl script that will allow 
a user to input different numerical parameters, based on which the 
script will perform different tasks, repeat certain steps, et c.

An example of what may need to be included in the input file:

wingspan = number
chord = number
grid type = text
velocity = number
angle of attack = number

et c., where any of these can have multiple values so the script can do 
iterations.

So my question: what's the best input file format to use for this type 
of thing? Easiest for me, the programmer? Easiest for the (professional) 
user? Most flexible?

- Joel



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

Date: Wed, 19 Feb 2003 14:51:19 +0100
From: Daniel Jaeggi <jaeggi@embl-heidelberg.de>
Subject: Memory usage/cleanup & hashes
Message-Id: <Pine.LNX.4.33.0302191439160.10814-100000@dag.embl-heidelberg.de>

Hi

I've got a problem with a reasonably sized Perl program that can have some
large and complex data structures (namely hashes of hashes (of hashes)).

The program runs well, produces all its output - the last line of code has
been executed. Except that the process keeps on running, sometimes for
quite a while... This is particularly annoying because the program in
question is running as a CGI script and this leads to zombie http server
processes running that sometimes need to be cleared manually.

I suspect that this is something to do with the use of the complex data
structures and Perl's internal memory cleanup. Can anyone shed any more
light on this problem? Is there any way of avoiding it (other than
rewriting the code massively)? Is there any way to exit the script quickly
(like hitting CTRL+C)? Why does Perl need to do this anyway, given that
hitting CTRL+C instantly returns all memory to the system without any
apparent side-effects?

Thanks in advance,

Daniel

PS I'm running Perl v5.6.1 on SuSE 7.3



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

Date: Wed, 19 Feb 2003 13:06:04 -0000
From: "Mikey" <PleaseDontThrowSpam@Me.com>
Subject: Re: Need Help with Pattern Matching
Message-Id: <b2vvd8$a07$1@wisteria.csv.warwick.ac.uk>


"Marc" <marc.beyer@gmx.li> wrote in message
news:b2uscm$1gbpk7$1@ID-123680.news.dfncis.de...
> Hi,
>
> regular expressions are your friend :-). Use this as your sort subroutine:
>
> sub make_sort {
> ($a =~ m/[0-9\.]*\s\d*\s([a-zA-Z ]*)\s\d\.\d+/)[0]
>   cmp
>   ($b =~ m/[0-9\.]*\s\d*\s([a-zA-Z ]*)\s\d\.\d+/)[0];
> }
>
> Note that this currently sorts on the first name (same as your "split"
would
> have done), if you want a sort on the last name you'd have use this regex:
>
> m/[0-9\.]*\s\d*\s[a-zA-Z ]*\s(\w*)\s\d\.\d+/
>
>
> Have fun,
>
> Marc
>
> P.S. I have no idea how many records you need to sort and in what
timeframe,
> this solution might be too slow for you.

Thanks Marc, but I asked for it to be sorted by height! (ascending)

DOB Cash Name Height

12.01.1963 100 John Smith 5.11
27.02.1955 200 Jimmy Dolan Andrews 5.8
16.03.1977 400 Johnny Barrosh 5.4
09.01.1987 200 Steve McHooter 5.5
01.02.1983 100 Blaro Van Daronimo 4.4

The number of records is very minimal so the timeframe is negligable.

Incidently, when I tried your idea as well as the following lines:
use strict;
use warnings;

I was getting "use of uninitialized value in string comparison" and the data
wasn't sorted as expected.

What is happening?

Thanks,

Mikey





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

Date: Wed, 19 Feb 2003 13:12:12 -0000
From: "Mikey" <PleaseDontThrowSpam@Me.com>
Subject: Re: Need Help with Pattern Matching
Message-Id: <b2vvon$a9j$1@wisteria.csv.warwick.ac.uk>


"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3E52FBF1.D875220@earthlink.net...
> Mikey wrote:
> > Benjamin Goldberg wrote:
> > > Mikey wrote:
> > > [snip]
> > > > I'm trying to sort the following data by Height:
> > > > (this data resides in store.dat, each field separated by a space)
> > > >
> > > > DOB Cash Name Height
> > > >
> > > > 12.01.1963 100 John Smith 5.11
> > > > 27.02.1955 200 Jimmy Dolan Andrews 5.8
> > > > 16.03.1977 400 Johnny Barrosh 5.4
> > > > 09.01.1987 200 Steve McHooter 5.5
> > > > 01.02.1983 100 Blaro Van Daronimo 4.4
> > > >
> > > > I can't work out a correct pattern matching line which will
> > > > successfully separate these fields.
> > >
> > > The problem is that the fields are seperated by spaces, and the Name
> > > field has a variable number of embeded spaces.
> > >
> > > Thus, you can't just split on spaces and get the 4th element after
> > > splitting.
> > >
> > > However... the height field is always the *last* field when
> > > splitting on whitespace, even if the number of fields before it
> > > vary.
> >
> > This is true but I also may want to access the oter fields later.
>
> What exactly are you asking for?  Are you trying to figure out how to
> parse the fields into variables?

I'm trying to seperate the patter *properly* in case I need to access
anything that isn't strictly the last field at a later date.

>    while( <IN> ) {
>       my ($dob, $cash, $name_height) = split ' ', $_, 3;
>       my ($name, $height) = $name_height =~ /(.*) (.*)/;
>       # do stuff with $dob, $cash, $name, height.
>    }
>
> > Would this type of pattern matching be possible despite the fact that
> > the separotors are spaces and a field can have random number of spaces
> > in it?
>
> As long as there's only *one* field which can have a random number of
> spaces in it, yes.
>
> >  >So, you can do the following:
> > >
> > >    open( FH, "<", "store.dat" ) or die $!;
> > >    print sort {
> > >       (split(' ', $a))[-1] <=> (split(' ', $b))[-1]
> > >    } <FH>;
> > >    __END__
> > >
> >
> > This compiles and runs but how do I print the newly sorted data?
>
> There's a print statement in there...  Does nothing get outputed to your
> screen when you run it?

Yes, it prints nicely..

> Or are you asking something else (eg, how do I store the newly sorted
> data, or maybe how do I extract the Cash field from each row of the
> newly sorted data, etc.)?

I would like to print out in order of height (ascending). This works. I
would then like to examine the sorted data and select to print certain data
items that fufil criteria.

For example, I may wish to code:
Print in order of height, all entries with cash equal to 200.

Or

Order by height and look up their name in a different file.

Would these things be possible with this method?

If not, what method is advised?

Thank-you,

Mikey




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

Date: Wed, 19 Feb 2003 12:41:23 +0000 (UTC)
From: "JohnShep" <go@way.com>
Subject: Redhat UTF the nightmare continues
Message-Id: <b2vu1i$fv$1@knossos.btinternet.com>

previously

> I've just got a new server and installed Redhat 8.0. But now many of
> my scripts are broken with UTF-8 errors. Can anyone tell me what I
> need to do to fix this.

Thanks to Benjamin Goldberg I have managed to fix the States.pm module.
However I'm finding that more and more of my scripts which worked fine on
Suse are broken under the Redhat environment. Some just die without warning,
many report UTF errors, Illegal hexadecimal digits etc. Unfortunately it's
too late to revert now as  the machine is a 100 miles away now locked in a
computer centre, my ISP recommended Redhat :-(
Is there a way of reconfiguring the env to be compatible with the scripts
and modules I use or must I track down every single compatibility problem ?

Thanks, John





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

Date: Wed, 19 Feb 2003 12:48:37 GMT
From: "H. Wade Minter" <minter@lunenburg.org>
Subject: Re: Redhat UTF the nightmare continues
Message-Id: <F2L4a.34651$If5.1079076@twister.southeast.rr.com>

JohnShep <go@way.com> wrote:
> previously

> Is there a way of reconfiguring the env to be compatible with the scripts
> and modules I use or must I track down every single compatibility problem ?

Have you tried exporting LANG="C"?

--Wade




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

Date: Wed, 19 Feb 2003 13:06:02 +0000 (UTC)
From: "JohnShep" <go@way.com>
Subject: Re: Redhat UTF the nightmare continues
Message-Id: <b2vvfq$mms$1@helle.btinternet.com>


"H. Wade Minter" <minter@lunenburg.org> wrote in message
news:F2L4a.34651$If5.1079076@twister.southeast.rr.com...
> JohnShep <go@way.com> wrote:
> > previously
>
> > Is there a way of reconfiguring the env to be compatible with the
scripts
> > and modules I use or must I track down every single compatibility
problem ?
>
> Have you tried exporting LANG="C"?

Tried it, no difference :-

$export LANG="C"
$perl test.pl

Illegal hexadecimal digit '     ' ignored at
/usr/lib/perl5/5.8.0/utf8_heavy.pl line 152, <DATA> line 3.

John




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

Date: 19 Feb 2003 11:37:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Returning the field list from DBI
Message-Id: <b2vq9f$q9f$1@mamenchi.zrz.TU-Berlin.DE>

Kåre Olai Lindbach  <barbr-en@online.no> wrote in comp.lang.perl.misc:
> On Tue, 18 Feb 2003 22:27:02 -0500, Benjamin Goldberg
> <goldbb2@earthlink.net> wrote:
> 
> >Sharon Grant wrote:
> >> Benjamin Goldberg wrote:
> >>>Jason Singleton wrote:
> >>>> Also how do I change the read position in the returned data? I
> >>>> don't want to return all records to the user at once I want it to
> >>>> display the returned data in pages like a search engine.
> 
> [snip alot useful]
> 
> >IMHO, the *best* way of doing this is to have the query for the first
> >page of data to fetch *all* the rows, but write them to a cache file (or
> >rather, a bunch of cache files, one per page of data).  Subsequent
> >requests would then read from those files.  This avoids the need to do
> >unportable things like LIMIT, and the need to add potentially expensive
> >things, like ORDER BY.
> 
> There is a disclaimer, though:
> 
> The longer you keep this buffer, and only look there, the more
> incorrect your data will be, if it is updated alot.

On the other hand, the data will be consistent throughout the
pages.  Showing parts of a database *while* it is updated can
result in an inconsistent image.

Anno


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

Date: Wed, 19 Feb 2003 11:49:24 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: Returning the field list from DBI
Message-Id: <g6q65vcgn5831spn4q973ppnobps87g5l9@4ax.com>

On Tue, 18 Feb 2003 22:27:02 -0500, in comp.lang.perl.misc, Benjamin Goldberg <goldbb2@earthlink.net> wrote:

>Sharon Grant wrote:
>> Benjamin Goldberg wrote:
>>>Jason Singleton wrote:
>>>> Also how do I change the read position in the returned data? I
>>>> don't want to return all records to the user at once I want it to
>>>> display the returned data in pages like a search engine.
>> 
>> SQL is a set-oriented data access language. The general advice
>> has always been that there should not be a need to return part
>> of a set. Instead the query should be refined to return a
>> smaller set
>> 
>>> There's two possible ways, both of which
>>> require support from the SQL driver.
>>>
>>> One is to use a LIMIT clause; this is the prefered way.
>>>
>>> The other is to use the ->func method on the statement handle, to
>>> tell the driver that you want to skip forward some number of records.
>>> I'm not sure what databases, if any, have this kind of functionality.
>>>
>>> There's sortof a third way -- simply read and discard as many records
>>> as you want to skip.  This is innefficient, but portable
>> 
>> All the above suggestions assume that the DBMS is going to
>> return the data in the same order each time, which an SQL DBMS
>> may not do unless:
>> - the query has an ORDER BY clause, and
>> - the column names in the ORDER BY clause specify a unique key
>> 
>> This is explained more eloquently in the PostgreSQL
>> documentation of the LIMIT clause:
>>  http://tinyurl.com/61r3
>
>Hmm, it sounds like it's saying that if a LIMIT clause is present, but
>you've left out ORDER BY, PostgreSQL will intentionally mangle the order
>of the data in such a way that LIMIT and OFFSET are useless for
>providing subsets of the data

Perhaps the LIMIT clause invokes optimisation algorithms which have the
side-effect of changing the sequence of unORDERed rows


>I seriously doubt that this is a common effect; I would expect that the
>only *normal* reasons why the order would be inconsistant are if rows
>are inserted/deleted/altered

If rows are being added, deleted or altered, there is an impact on the
user's view of the data in any case, with any database, not only SQL

>or if an index is added/removed/remade for
>a table, or something else is done which alters the tables in question,
>or alters their metadata

Or it's one of those modern self-maintaining DBMS which automatically,
dynamically reorganises itself by shuffling the way rows are stored in
pages whenever it can find a few spare CPU cycles

Whether it's common or not, it's an implementation issue. As a
specification, SQL does not require a predictable sequence unless the
query has an ORDER BY clause


>> Now, since a uniquely keyed ORDER BY clause is required in any
>> case, paging can be implemented (portably) by saving the key
>> of the last row of the current page, and including that key in
>> the search conditions of the WHERE clause of the query which
>> is to produce the next page
>
>Are you suggesting something like:
>
>   my $sth = $dbh->prepare(q(
>      SELECT * FROM table
>      WHERE primarykey > ?
>      ORDER BY primarykey
>  ));
>   $sth->execute( $where_last_search_finished );
>   while( my $data = $sth->fetchrow_hashref ) {
>      output($data);
>      $key_of_last_row_output = $data->{primarykey};
>      last if ++$rows >= $items_per_page;
>   }
>   $sth->finish;
>   # store $key_of_last_row_output somewhere.
>
>?

Yes, and the WHERE clause will include the search conditions matching
the end-user's original query, as well as the paging key

> I suppose it would work, but if the database implementation does a
>lot of prefetching (transfers large numbers from the database server
>process to the client, even before they're fetched), there's still a bit
>of innefficiency here (unless a LIMIT clause is used, but some databases
>don't support that)

And some might process the entire large result set even if the query has
a LIMIT clause, so the programmer gets the coding benefit of having the
results trimmed, but not any performance benefit

>Plus of course there's your other note:
>
>> The syntax of the search conditions gets a bit verbose for a
>> multi-column key, but that's part of the cost of SQL
>
>.....
>
>IMHO, the *best* way of doing this is to have the query for the first
>page of data to fetch *all* the rows, but write them to a cache file (or
>rather, a bunch of cache files, one per page of data).  Subsequent
>requests would then read from those files.  This avoids the need to do
>unportable things like LIMIT, and the need to add potentially expensive
>things, like ORDER BY

Yes, and avoid the overhead of processing a large result set every time
the user requests the next page

The cache could be stored in a temporary database table, indexed by row
number. Paging then becomes a simple matter of ORDERing BY the row
number with a WHERE clause specifying the exact row numbers for the top
and bottom of each page

-- 
Sharon


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

Date: Wed, 19 Feb 2003 13:30:56 -0000
From: "Mikey" <PleaseDontThrowSpam@Me.com>
Subject: Re: Unsuccesful "Print"
Message-Id: <b300u0$b6r$1@wisteria.csv.warwick.ac.uk>


"Jay Tilton" <tiltonj@erols.com> wrote in message
news:3e52f4e4.32989123@news.erols.com...
> "Mikey" <PleaseDontThrowSpam@Me.com> wrote:
>
> : This is a cut down version that has the exact same problems - it wont
output
> : anything!
> :
> : (perl perlfile.pl -h yields nothing, as does the -h anything option)
> : (perl perlfile.pl -x will give Unknown option: x)
> :
> : use strict;
> : use Getopt::Std;
> : my($opt_h, $opt_a);
> : getopts('ha:');
> : if ( $opt_h ) {
> :  print "\nUsage: perlfile [ options ] arg\n";
> : }
> :
> : if ( $opt_a ) {
> :  print "\nYou entered $opt_a\n";
> : }
>
> getopts() will assign values to package variables, not lexicals.
>
> Change
>
>     my($opt_h, $opt_a);
>
> to
>
>     our($opt_h, $opt_a);
>

If I do this, I get errors:

Global symbol "$opt_a" requires explicit package name at ./perlfile
Global symbol "$opt_h" requires explicit package name at ./perlfile

It's getting worse, why is that?

It's being run by Perl, version 5.005_03 built for sun4-solaris

Thanks,

Mikey




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

Date: Wed, 19 Feb 2003 05:50:50 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Uploading a file
Message-Id: <Xns9327459ADAB4Bsdn.comcast@216.166.71.239>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

the_game_is_never_over@yahoo.co.uk (g) wrote in
news:2059e247.0302190257.69aecec2@posting.google.com:

> I put the if else loop in my code, but I get an error saying use
of
> uninitialized value in -T. why does this happen??
> 
> 
> 
> #!\usr\bin\perl\bin\perl.exe -w
> 
> 
> use CGI qw/:standard/;
> use CGI::Carp 'fatalsToBrowser';
> 
> $in = new CGI();
> 
> if (-T $in) {


What Gunnar meant was that -T might be the operator that you were
looking for to determine whether a file was text or not, not that you
should randomly toss a -T into your program without understanding
what it meant.  He even gave you a pointer into the documentation. 
You should read it.

- -- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13

iD8DBQE+U293Y96i4h5M0egRAliCAKCh9YJEdjxCpc3NwzqfGPb8qakaywCePnql
MtyxJ+MLCoRUjK/oqeDEQek=
=E/ny
-----END PGP SIGNATURE-----


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

Date: Wed, 19 Feb 2003 05:20:08 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: Uploading a file
Message-Id: <3E537678.1070406@indra.com>

See my comments below ...

g wrote:
> I put the if else loop in my code, but I get an error saying use of
> uninitialized value in -T. why does this happen??
> 
> 
> 
> #!\usr\bin\perl\bin\perl.exe -w
> 
> 
> use CGI qw/:standard/;
> use CGI::Carp 'fatalsToBrowser';
> 
> $in = new CGI();
> 
> if (-T $in) {
          ^^^  Huh?  $in is a CGI object, not a file

>       
> $INPUT = $in->param('original');
> $outtie = $in->param('newname');
> $OUTPUT = ">./$outtie";
> 
> open (OUTPUT) || die "Unable to open file for writing";
               ^^^^ Where is the file name?

[ snipped code]

1.  You should **always** use strict in your code (perldoc strict).
2.  Read the docs on file test operators, and file processing (open, etc).

--
Ron Reidy
Oracele DBA



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

Date: 19 Feb 2003 11:08:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: use DBI;
Message-Id: <b2vojl$o03$1@mamenchi.zrz.TU-Berlin.DE>

For heaven's sake, provide some context.  No-one likes to dig through
the thread just to find out what you are talking about.

g <the_game_is_never_over@yahoo.co.uk> wrote in comp.lang.perl.misc:
> Hi thanks for you help so far, looks like I now can connect to the
> database but I get a error message saying malformed header from
> script. Bad header=. it then displays the first 2 fields from by
> database (in my error log)   What does that mean???

"Malformed header..." isn't a Perl error message.

It means that you are using the script to produce HTML (a CGI,
presumably), but didn't produce the requisite headers.  This is
not a Perl problem, though Perl has modules that can help with it.
See "perldoc -q cgi" for this aspect.  Otherwise, consult a newsgroup
that concerns itself with HTML and/or CGI.

Anno


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

Date: 19 Feb 2003 12:17:21 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: use DBI;
Message-Id: <b2vskh$p59$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Helgi Briem:

> On 18 Feb 2003 18:13:58 GMT, Abigail <abigail@abigail.nl>
> wrote:

>>Just because it isn't "necessary" doesn't make an exit() at the end
>>of the program cargo cult, just like using parens where not required,
>>or an $_ where not required make "cargo cult".
> 
> I though the definition of "cargo cult" was using something
> in a program because you saw it somewhere else without
> knowing why you are using it.
> 
> Do you use exit(0) a lot?  And if so, what for?

I can't speak for Abigail, but I use it from time to time in various
situations. Sometimes it's necessary, sometime's it's not.

There are situations where an implicit exit(0) happens and where it's
useful. I found this in one of my scripts:

    while (@ARGV) {
        my $param = get_wma(shift) or
            $exit |= 1, next;
        my $err = encode_wma($param);
        warn "Error on file $param->{wma}\n" if $err;
            $exit |= $err;
    }
    exit $exit;

So basically $exit is the ORing of a serious of values returned by
system()s (deep down in the called subroutines). I can't simply bail out
on the first failure since the above works on a series of files in @ARGV
and I want it to process as many as possible. However, if one fails
return value is something other than zero.

However this is not quite the same as the issue debated herein. An
exit(0) can serve as a comment for me, the programmer. Whenever I see it I
know that the program worked fine when it reached a particular line.
Often I have a usage() function that dumps the command-lines to stderr
when the script was called with -h. I explicitely put an exit(0) at the
end of these functions. A simple exit() would achieve the same, but why
not adding the zero? People have different cognitions and I sense that
mine works slightly better when I add this zero (because it stands out
nicely).

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Wed, 19 Feb 2003 11:33:27 GMT
From: "Edward Wildgoose" <Ed+nospam@ewildgoose.demon.co.uk@>
Subject: wanted: BZIP2 module for Win32 and Linux
Message-Id: <bYJ4a.1260487$TJ.177153@post-02.news.easynews.com>

Apologies if this is the wrong place.  I have a need for a BZIP2 module in
the style of the current zlib library - in fact since the interface is so
similar I wonder if it wouldn't be possible to broadly lift the zlib code
and slot in bzip..?

Anyway, this would be contributed back to CPAN for all to use, but I
particularly have a need for the stream compression functions with "partial
flush", etc, ie so I can use it for compressing a real time data stream.  It
must also install successfully on win32 and linux (at least).

If someone had some freetime then I think this would be an excellent
addition to perl anyway, however, I would also be willing to pay "hobbyist"
rates for the work, ie 100 bucks or so.

If you want to contact me off-list then please send mail to
bzipwork@wildgooses.com

Thanks

Ed W




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

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


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