[19931] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2126 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 13 18:10:39 2001

Date: Tue, 13 Nov 2001 15:10:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005693014-v10-i2126@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 13 Nov 2001     Volume: 10 Number: 2126

Today's topics:
        Newbie Question, pls HELP!! (bhattey)
    Re: Perl - MySQL question <tsee@gmx.net>
    Re: Perl.dl v.v. Perl.exe; it's stability and what is t <tsee@gmx.net>
    Re: pretty-print perl code? (Mike Eggleston)
        Pretty-printing CSS <darkon@one.net>
    Re: Reading from a hash list <tsee@gmx.net>
        Redirect STDOUT from a Unix script to a perl program an (Marty Gagnon)
    Re: Redirect STDOUT from a Unix script to a perl progra <mikesl@wrq.com>
    Re: Return from subroutine behaving unexpectedly (Jay Tilton)
        stacked if statements <tam@patriot.net>
    Re: stacked if statements <Tassilo.Parseval@post.rwth-aachen.de>
    Re: stacked if statements (John J. Trammell)
    Re: stacked if statements <uri@stemsystems.com>
    Re: stacked if statements (Damian Conway)
    Re: stacked if statements <bruce@sportingpulse.com>
    Re: Unencoding <mgjv@tradingpost.com.au>
        unresolved symbol Perl_Tstack_sp_ptr from Fcntl.so when (Kong Li)
        Vignette::Transfer module (Ticha)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 13 Nov 2001 11:33:35 -0800
From: bhattey@hotmail.com (bhattey)
Subject: Newbie Question, pls HELP!!
Message-Id: <704bbfe6.0111131133.8a22897@posting.google.com>

Hello all,

I have a small CGI script. Used to be working fine, but out of
nowhere, now I am getting the following error in the script. Any
advise on where the problem lies would be very helpful.


Software Error:

Operation `eq': no method found, left argument in overloaded package
CGI::Cookie, right argument has no overloaded magic at ./dscipt.cgi
line 527.


Here is the snippet of the code. (pls notice the commented line
halfway though the code)

sub authenticate {
$form_password = $q->param(password);
open (USERFILE, "$user_file") || die "Error opening user file.  $!\n";
$user_matched = 0;
while (<USERFILE>) {
chop($_);
($password, $user, $u_search, $u_add, $u_modify, $u_delete,
@extra_user_fields) = split(/\|/, $_);
if ($q->param(user) eq $user) {
$user_matched = 1;
$username = $user;
$user_add = $u_add;
$user_modify = $u_modify;
$user_search = $u_search;
$user_delete = $u_delete;
if (&auth_encrypt ($form_password, $password) eq $password) {
$cookie = $q->cookie(-NAME=>'user',-VALUE=>"$user",-EXPIRES=>'+3d');
} # End of if passwords match
} # End of if username matches
} # End of While
close (USERFILE);
############## THE LINE BELOW SEEMS TO MAKE THE ERROR ##############
if ($user_matched == 1 && $cookie eq "") {
$footer = "login";
$title = "Login";
$error_message = "Your password did not match your user name!";
&access_problem($error_message);
exit;    }
if ($user_matched == 0) {
$footer = "login";
$title = "Login";
$error_message = "Your user name was not found!";
&access_problem($error_message);
exit;    }
print header(-cookie=>[$cookie]);
$set_cookie = "yes";
$message = "User \"$username\" is now logged in";
$title = "Main Menu"; 
$user = $username;
&print_default($title, $message);
exit;
}


Thanks in advance for any of your suggestions.


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

Date: Tue, 13 Nov 2001 20:19:43 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Perl - MySQL question
Message-Id: <9srrnd$vip$04$1@news.t-online.com>

"echnathon" <echnathonh@yahoo.com> schrieb im Newsbeitrag
news:9srpv0$tji$1@rivage.news.be.easynet.net...
| I need suggestions: I would like subscribers to my mailinglist (written in
| Perl) to end up in a MySQL database, for administrative purposes.
|
| What would be a good place to start ? I suppose modifying the
| user-subscription script ?
|
| All tips welcomed ! Thanks !

A generally good place to start is cpan.org as well as google.

Install MySQL.
Install DBI if its not in the core distribution.
Same for DBD::MySQL.

Then read their documentation.

Well, then I'd modify the subscription script as well as the script to send
mail if there is one... Otherwise it won't work.

Anyway, you might want to ask some more specific questions to get more
useful answers :)

No need to crosspost this.

HTH a bit,
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m





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

Date: Tue, 13 Nov 2001 21:18:25 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Perl.dl v.v. Perl.exe; it's stability and what is the most recent version?
Message-Id: <9ss133$8nt$07$1@news.t-online.com>

"Jongkees" <robert@context.nl> schrieb im Newsbeitrag
news:38b8bfdb.0111130827.14ba5bfd@posting.google.com...
| Hello,
|
| I'm not yet so formiliar whith Perl, but I have some questions
| conserning the use of perl on a web-server. Who can help me?

Hello,

most people around here.

| 1)  I Like to implement a version of Perl on our web-server, but can
| anyone inform me about the differences between perl.dll and perl.exe.
| If I want an perl-script running whith use of an web-page-call how can
| I call this.

This is not a Perl question. This is a web server question. Look for a
newsgroup about webservers.

| 2)  What is the most recent version of Perl, and what are the
| differences between that version and Perl 5.005. Is the script written
| for version 5.005 backwards complatible for the newest version.

Install the newest Perl (5.6.1 and don't tell me about development
releases).
type perldoc perldelta in the shell. Perl 5.6.1 should be backwards
compatible with older versions of Perl5. It does introduce new features,
though.

| 3)  Does somebody know about the stability of this new version versus
| the previous one.

It is also (obviously) the least buggy version, AFAIK.
Well, least buggy is not quite right. Most Perl releases are very stable,
but there is a reason these guys keep working on perl and release new
versions, so upgrade. I heard 5.6.0 was rather buggy, though.

| 4)  What is the best way to make use of perl on a web-server. I saw
| about ActivePerl on www.activestate.com, but than I also have to make
| use PerlEx to use this on a web-server. Is this corret?

Install ActivePerl and Apache. This, again, is not a Perl language question.

HTH,
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m





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

Date: Tue, 13 Nov 2001 19:27:58 GMT
From: mikee@kensho.eggtech.com (Mike Eggleston)
Subject: Re: pretty-print perl code?
Message-Id: <slrn9v2t1u.dbb.mikee@kensho.eggtech.com>

On Tue, 13 Nov 2001 17:22:28 +0000, Miguel Manso <mmanso@yahoo.com> wrote:
> perltidy is your friend
> 
> In article <slrn9v2kg8.bqg.mikee@kensho.eggtech.com>, "Mike Eggleston"
><mikee@kensho.eggtech.com> wrote:
> 
>> Is there a way, outside of emacs, to pretty-print perl code?
>> 
>> Mike

Thanks.


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

Date: Tue, 13 Nov 2001 22:39:09 -0000
From: David Wall <darkon@one.net>
Subject: Pretty-printing CSS
Message-Id: <Xns9158B361F489Ddarkononenet@207.126.101.97>


I've been using the following program for formatting CSS in web pages.  
I've found it pretty useful in tidying up all the CSS I've had to 
read/edit.  (Sometimes people use IE to get a copy of a page I created for 
them and then make changes with a WYSI(not)WYG tool. The combination of 
the two completely rewrites the contents in an apparent attempt to make it 
unreadable by humans.  HTML Tidy cleans up the HTML, but leaves CSS alone. 
Hence this program, which I have hooked into my editor.)

If anyone likes it, here it is, with the caveat that there may be serious 
flaws in it, and I take no responsibility for any bugs you may encounter.  
As I said, it works just fine for me, but generally it's reformatting CSS 
which I wrote, so it may only work well with *my* CSS....

Actually I think I should just write a parser for CSS (unless there's 
already one), but I'm still slacking off on learning more about parsers. 

I'm posting in clpm instead of comp.infosystems.www.authoring.stylesheets 
because I'd rather have it slapped down here instead of spreading it 
around like a Matt Wright script. :-)



# This program is intended for formatting CSS.
# Among the assumptions made about the input are:
# * the CSS syntax is already correct
# * HTML tags are lowercase, or case insensitive
# * CSS property names are lowercase
# * CSS property statements end with a ;
# * properties don't contain embedded :{};|+>
# * comments precede a rule, i.e; not like 
#       h1 {font-size: 2em;} /* top level */
#   but instead like
#       /* top level */
#       h1 {font-size: 2em;} 
#   or 
#       h1 { /* top level */
#           font-size: 2em;
#       }

use strict;
use warnings;

# used to indent properties within rules
my $indent = "  ";

undef $/;
my $css = <>;

for ($css) {
    s/\s+/ /g;                  # compress spaces
    s/\s*([{}:;,|>])\s*/$1/g;   # delete space(s) around  {}:;,|+>
    s|([^;])}|$1;}|g;      #end last property with ; (in case we add more)
    s/,/, /g;                   # add a space after ,
    s/([|>+])/ $1 /g;           # add a space around |>+
    s/{/ {\n${indent}/g;        # \n$indent after {
    s/;([^}])/;\n${indent}$1/g; # indent multiple properties
    s/}/\n}\n/g;                # \n after }
    s|\*/\s*|*/\n|g;            # \n after comment
}

my @css = split /\n/, $css;
undef $css;

my @tags = qw|address applet area a base basefont big blockquote body br
  b caption center cite code dd dfn dir div dl dt em font form h1 h2 h3 h4
  h5 h6 head hr html img input isindex i kbd link li map menu meta ol 
  option param pre p samp script select small span strike strong style 
  sub sup table td textarea th title tr tt ul u var|;

my $comment = 0;
foreach ( @css ) {

    if ( /;$/ ) {    # a property declaration
        s/:/: /;   # properties assumed to have only one :
        # lowercase property names (before the ':')
        s/^([^:]+:)/lc $1/e;
    }
    elsif ( /{$/ ) {    # a rule declaration
        foreach my $tag (@tags) {    #lowercase tags
            s/^($tag[, :.[])/ lc($1)/ei;
            s/( $tag[, :.[])/ lc($1)/gei;
        }
    }
    if ( $comment ) {    # previous line was a comment
        s/^\s*//        if m|{$|;    # this line starts a rule
        s/^\s*/$indent/ if m|;$|;    # this line is a property
    }
    $comment = m|\*/$| ? 1 : 0; # does this line end a comment?

}

print join "\n", @css;


__END__


-- 
David Wall
darkon@one.net


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

Date: Tue, 13 Nov 2001 21:31:40 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Reading from a hash list
Message-Id: <9ss134$8nt$07$3@news.t-online.com>

"Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> schrieb im
Newsbeitrag news:9sreca$9ha$04$1@news.t-online.com...
| On Tue, 13 Nov 2001 16:01:39 +0100, Robert wrote:
| > Thanks for your replay,
| > how could i read the data if i use a for loop or foreach or while loop.
|
| Assuming $hash_ref is the reference to a hash of hashes:
|
| 1 for my $key (keys %{$hash_ref}) {  # or just %$hash_ref
| 2     print "$key: \n";
| 3     for (keys %{$hash_ref->{$key}}) {
| 4         print "\t", $hash_ref->{$key}{$_}, "\n";
| 5     }
| 6 }
|
| In line 3 you can't shortcut this to %$hash_ref->{$key} since Perl would
| mess up the precedence.
| Alternatively in live 4: '$hash_ref->{$key}->{$_}'

May I suggest using this instead?

for my $key ( keys %$hash_ref ) {
    print "$key: \n";
    my $inner_hash_ref = $hash_ref->{$key};
    for ( keys %$inner_hash_ref ) {
        print "\t", $inner_hash_ref->{$_}, "\n";
    }
}

It may not matter for small hashes, but it becomes a bit faster for a large
number of inner hash keys because in your version, the outer hash lookup is
done for each access.
(I bet you knew, but the OP probably didn't.)

Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m





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

Date: 13 Nov 2001 13:41:29 -0800
From: mgagnon@informix.com (Marty Gagnon)
Subject: Redirect STDOUT from a Unix script to a perl program and then redirect back to script
Message-Id: <232f9abe.0111131341.dd0ddaf@posting.google.com>

I have a shell script that prompts for input and then reads the input

I want to automate a script by redirecting the prompts to a perl script,
which will decide the correct response, and then send the response back
to the shell script

I thought I could just do something like
"stub | perl res.pl" and when res.pl writes back out to STDOUT via "print"
then "stub" will pick it up with it's "read" but this isn't the case.

Any help is appreciated.


shell script: stub
-------------------------
#!/bin/sh
echo "enter name "
read name
echo "enter phone "
read phone

perl script: res.pl
---------------------------
#!/usr/bin/perl
$input = <STDIN>;
#some logic here to determine the correct response
print $response

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


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

Date: Tue, 13 Nov 2001 22:04:27 GMT
From: Michael Slass <mikesl@wrq.com>
Subject: Re: Redirect STDOUT from a Unix script to a perl program and then redirect back to script
Message-Id: <m3pu6m49az.fsf@thneed.na.wrq.com>

mgagnon@informix.com (Marty Gagnon) writes:

>I have a shell script that prompts for input and then reads the input
>
>I want to automate a script by redirecting the prompts to a perl script,
>which will decide the correct response, and then send the response back
>to the shell script
>
>I thought I could just do something like
>"stub | perl res.pl" and when res.pl writes back out to STDOUT via "print"
>then "stub" will pick it up with it's "read" but this isn't the case.
>
>Any help is appreciated.
>

I don't think that sort of circular pipe works.  Most folks on this
list will advise you to port your whole shell script to perl, but if
you're attached to the script, why don't you just invoke perl from
within the script, and then have perl look for command-line args
rather than reading from stdin:

>
>shell script: stub
>-------------------------
>#!/bin/sh
>echo "enter name "
>read name
>echo "enter phone "
>read phone
>
response=`perl res.pl $name $phone`
# use the response

>perl script: res.pl
>---------------------------
>#!/usr/bin/perl
my($name, $phone) = @ARGV;
>#some logic here to determine the correct response
>print $response
>
>-----------------------------



-- 
Mike


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

Date: Tue, 13 Nov 2001 22:22:19 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Return from subroutine behaving unexpectedly
Message-Id: <3bf1718d.317903112@news.erols.com>

"Andrew Harton" <andrew_harton@agilent.com> wrote:

>"Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote
>>
>> [snipped massive amount of Perl code]
>>
>> When nobull asked for a complete script he (explicitely) asked for a
>> small one. No one here really wants to dig through 180 or so lines of
>> code written by someone else with someone else's logic.
>
>Sorry, I didn't realise that 160 or so lines was a "massive amount of Perl
>code".  I felt that I had to put all of it in there because of what it does.

For the purpose of posting to clpm, consider anything more than a
screenful to be massive.

Reduce the code to the *barest* minimum necessary to exhibit the
undesired behavior.  At this program's essence, what it does (or
does not do) is print a string returned from a sub.  Everything
except DialogBox() is concerned with getting user input[1] to
create that string, and can be eliminated from suspicion almost
immediately.

The minimum code would be...

  #!/usr/bin/perl
  use strict;
  use warnings;
  use Win32::Console;

  #does_print();
  does_not_print();

  sub does_print {
    if( my $val = DialogBox() ) {
      print "Selection : $val \n";
    }
  }

  sub does_not_print {
    my $val = DialogBox();
    print "Selection : $val \n";
  }

  sub DialogBox {
    my $OUT = new Win32::Console(STD_OUTPUT_HANDLE);
    my $selection = "'this is my selection'";
    print "Returning $selection\n";
    return $selection;
  }

Regardless of subjective definitions of "massive" and "small,"
reducing the program's size by an order of magnitude certainly
brings it closer to small.

>I haven't had a problem with returns from subroutines before,

There is no problem with the return here, either.  It is there.
You can see it if you change 'print' to 'print STDERR'.  Conclude
that something in the does_not_work() case is stealing the
ability to print to STDOUT, not that the return is being mangled.

The fundamental question of why these two cases behave
differently remains, but those who may help will be more inclined
to do so.

[1]Those who may help will also be *much* more inclined to do so
when the program can exhibit the undesired behavior without user
input.



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

Date: Tue, 13 Nov 2001 15:30:24 -0500
From: Tom McDonough <tam@patriot.net>
Subject: stacked if statements
Message-Id: <3BF182E0.63BB2646@patriot.net>

Registrants for a conference will fill out my form and my script will
confirm their registration info.  There are three sessions.  Registrants
may register for one, two or all.  Selection of a single session or
'all' works fine but if someone registers for two, only the later
session is printed.  I'll bet this is Perl 101 but I'm learning as I go.

Here's my snippet:

print "You have registered for:\n";
if ($form{'session'}='all') {
        print "All sessions\n";
}
else {
        if ($form{'session'}=~'one') {
                print "January session\n";}
        if ($form{'session'}=~'two') {
                print "February session\n";}
        if ($form{'session'}=~'three') {
                print "March session\n";}
}



--
Tom McDonough
202.415.0582
Be a better dad!  Visit http://www.dadsden.net/




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

Date: Tue, 13 Nov 2001 21:48:02 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: stacked if statements
Message-Id: <9ss0u2$557$02$1@news.t-online.com>

On Tue, 13 Nov 2001 15:30:24 -0500, Tom McDonough wrote:
> Registrants for a conference will fill out my form and my script will
> confirm their registration info.  There are three sessions.  Registrants
> may register for one, two or all.  Selection of a single session or
> 'all' works fine but if someone registers for two, only the later
> session is printed.  I'll bet this is Perl 101 but I'm learning as I go.
> 
> Here's my snippet:
> 
> print "You have registered for:\n";
> if ($form{'session'}='all') {
>         print "All sessions\n";
> }
> else {
>         if ($form{'session'}=~'one') {
>                 print "January session\n";}
>         if ($form{'session'}=~'two') {
>                 print "February session\n";}
>         if ($form{'session'}=~'three') {
>                 print "March session\n";}
> }

There is a logical error in your code. $form{session} is a scalar
variable hence it can only hold either of 'all', 'one', 'two' or 'three'
unless you sort of concatenate these values together.

Secondly, you are testing for equality of strings so you should not use
m// but eq instead. More to that, your first if-statement is not doing
what you expect. This is probably a typo (you should not do that anyway,
but copy and paste your *working* code). It will assign 'all' to
$form{session} and since this assignment will return 'all' itself this
condition would always be true.

In short: use ($a eq 'string') to do string-comparison where no regexes
are needed and secondly find another logic to store your data. It will
only print the third session since $form{session} is overwritten with
'three' after it already contained 'two'.

Tassilo
-- 
Knowledge is power -- knowledge shared is power lost.
		-- Aleister Crowley


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

Date: Tue, 13 Nov 2001 15:02:57 -0600
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: stacked if statements
Message-Id: <slrn9v32mr.bkd.trammell@haqq.el-swifto.com>

On Tue, 13 Nov 2001 15:30:24 -0500, Tom McDonough <tam@patriot.net> wrote:
> Registrants for a conference will fill out my form and my script will
> confirm their registration info.  There are three sessions.  Registrants
> may register for one, two or all.  Selection of a single session or
> 'all' works fine but if someone registers for two, only the later
> session is printed.  I'll bet this is Perl 101 but I'm learning as I go.
> 
> Here's my snippet:
> 

First: don't forget to turn on warnings and "use strict;".

> print "You have registered for:\n";
> if ($form{'session'}='all') {

This is an assignment, so the "if" is always true.  Use 'eq', not
'==' (or even '=').  You blew this one twice in one shot!  :-)

>         print "All sessions\n";
> }
> else {
>         if ($form{'session'}=~'one') {

'one' should be "/one/", or you should use 'eq', not =~.

>                 print "January session\n";}
>         if ($form{'session'}=~'two') {
>                 print "February session\n";}
>         if ($form{'session'}=~'three') {
>                 print "March session\n";}
> }

You have some weird convention for curly-braces going on there.
A more standard usage is to have them line up, either vertically
or horizontally, e.g.:

 if ($form{'session'} =~ /three/) { print "March session\n"; }

or

 if ($form{'session'} =~ /three/)
 {
     print "March session\n";
 }



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

Date: Tue, 13 Nov 2001 21:14:16 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: stacked if statements
Message-Id: <x7r8r2id8j.fsf@home.sysarch.com>

>>>>> "JJT" == John J Trammell <trammell@haqq.hypersloth.invalid> writes:

  >> if ($form{'session'}=~'two') {
  >> print "February session\n";}

  JJT> You have some weird convention for curly-braces going on there.
  JJT> A more standard usage is to have them line up, either vertically
  JJT> or horizontally, e.g.:

  JJT>  if ($form{'session'} =~ /three/) { print "March session\n"; }

  JJT> or

  JJT>  if ($form{'session'} =~ /three/)
  JJT>  {
  JJT>      print "March session\n";
  JJT>  }

and both of those are wierd too. perl style standard (and the coding
style police are watching you!) is:

	if ( blah ) {

		blah ;
	}

you will only get a ticket (hmm, would a -w warning be enough?) this
time. next time, a sentence to code in java for 2 years.

:)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 13 Nov 2001 21:21:13 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: stacked if statements
Message-Id: <9ss2s9$it3$1@towncrier.cc.monash.edu.au>

Tom McDonough <tam@patriot.net> writes:

> I'll bet this is Perl 101 but I'm learning as I go.

Good for you. There's certainly nothing wrong with the general *structure*
of your snippet, but you do have a logical bug with:

	if ($form{'session'}='all') {

which should surely be:

	if ($form{'session'} eq 'all') {

or perhaps:

	if ($form{'session'} =~ 'all') {

You want to compare strings ('eq' or '=~'), not assign to the variable ("=").


Oh, and it's more idiomatic to write:

	if ($form{'session'} =~ /one/) {
	     print "January session\n";}

rather than:

	if ($form{'session'} =~ 'one') {
	     print "January session\n";}

It makes no difference to the behaviour of the code, of course,
but the unorthodox use of a literal string in a pattern match
may confuse less-experienced Perl programmers who read your code.

In fact, if the printing is the only thing you need to do for each
possible value, I'd be inclined to write the tests like this:

        print "January session\n"   if $form{'session'} =~ /one/;
        print "February session\n"  if $form{'session'} =~ /two/;
        print "March session\n"     if $form{'session'} =~ /three/;

which saves screen space and lines everything up neatly
(so the structure of your code can be more easily discerned).

All the best,

Damian


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

Date: Wed, 14 Nov 2001 09:41:18 +1100
From: "Bruce Irvine" <bruce@sportingpulse.com>
Subject: Re: stacked if statements
Message-Id: <20011114.094112.2058657199.5483@sportingpulse.com>

Damian, 

Is it true that Perl 6 will have a "switch/Select Case" statement for
this type of code.

Bruce.


In article <9ss2s9$it3$1@towncrier.cc.monash.edu.au>, "Damian Conway"
<damian@cs.monash.edu.au> wrote:

> Tom McDonough <tam@patriot.net> writes:
> 
>> I'll bet this is Perl 101 but I'm learning as I go.
> 
> Good for you. There's certainly nothing wrong with the general
> *structure* of your snippet, but you do have a logical bug with:
> 
> 	if ($form{'session'}='all') {
> 
> which should surely be:
> 
> 	if ($form{'session'} eq 'all') {
> 
> or perhaps:
> 
> 	if ($form{'session'} =~ 'all') {
> 
> You want to compare strings ('eq' or '=~'), not assign to the variable
> ("=").
> 
> 
> Oh, and it's more idiomatic to write:
> 
> 	if ($form{'session'} =~ /one/) {
> 	     print "January session\n";}
> 
> rather than:
> 
> 	if ($form{'session'} =~ 'one') {
> 	     print "January session\n";}
> 
> It makes no difference to the behaviour of the code, of course, but the
> unorthodox use of a literal string in a pattern match may confuse
> less-experienced Perl programmers who read your code.
> 
> In fact, if the printing is the only thing you need to do for each
> possible value, I'd be inclined to write the tests like this:
> 
>         print "January session\n"   if $form{'session'} =~ /one/; print
>         "February session\n"  if $form{'session'} =~ /two/; print "March
>         session\n"     if $form{'session'} =~ /three/;
> 
> which saves screen space and lines everything up neatly (so the
> structure of your code can be more easily discerned).
> 
> All the best,
> 
> Damian


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

Date: Tue, 13 Nov 2001 22:20:16 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Unencoding
Message-Id: <slrn9v375p.6ia.mgjv@verbruggen.comdyn.com.au>

On Tue, 13 Nov 2001 16:36:26 GMT,
	E.Chang <echang@netstorm.net> wrote:

> Incidentally, I find that the most interesting and informative threads 
> are those that pick up on some point in a question or response and 
> delve more deeply into it, as this one did on the EBCDIC topic.  

Indeed. Digressions like these provide some signal in the noise,
unless they somehow end in an exchange of flames. My apologies to
the readers of the group for that. I'll try to not respond to flame
fodder next time.

To come back to the topic: Is there anyone with an EBCDIC machine
reading this that could test that code either to confirm my suspicion
that it won't work, or to prove perl more portanle than that (doubt
it). If it doesn't work, I might try to work up a patch for Lincoln
Stein, since he uses this stuff in CGI.pm as well.

Martien
-- 
                                | 
Martien Verbruggen              | The world is complex; sendmail.cf
Trading Post Australia Pty Ltd  | reflects this.
                                | 


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

Date: 13 Nov 2001 11:32:53 -0800
From: likong@email.com (Kong Li)
Subject: unresolved symbol Perl_Tstack_sp_ptr from Fcntl.so when invoking perl via Java
Message-Id: <9e121089.0111131132.1cd98039@posting.google.com>

env: solaris 5.8, jdk 1.3.0_02 HotSpot client VM, mixed mode.  perl
5.6.1 built for sun4-solaris-thread-multi.

We have a multi-threaded Java application that invokes perl engine on
a few threads (we use those perl API perl_parse(), etc.).  If we
invoke the Java application directly, we always get the following
errors:

ld.so.1: /usr/java/bin/../bin/sparc/native_threads/java: fatal:
relocation error: file
/opt/usr/local/lib/perl5/5.6.1/sun4-solaris-thread-multi/auto/Fcntl/Fcntl.so:
symbol Perl_Tstack_sp_ptr: referenced symbol not found

We do have the correct LD_LIBRARY_PATH set.  The Java application
already loads libperl.so before encountering the above errors.  The
symbol Perl_Tstack_sp_ptr is actually defined in libperl.so.  All C
related files (including JNI and perl) are compiled with -KPIC.

We do not have this problem if we invoke a C program which then
invokes JVM.  We can invoke the standalone perl as a process to run
the script without any problem.

Both approaches (go straight to Java and from C to Java) have the same
set of .so files loaded.

Any ideas or hints or suggestions are appreciated.  Please reply by
email directly.  I will summarize if there is sufficient interest.

Thanks.

Kong


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

Date: 13 Nov 2001 13:15:53 -0800
From: ticha@consultant.com (Ticha)
Subject: Vignette::Transfer module
Message-Id: <f4c1ae7.0111131315.272200a0@posting.google.com>

All,

Is there anyone out there using Vignette (Story Server or V/5)?

I have written a perl Module to help manage the process of
transferring projects between CMSs as well as solve a few other
problems which have arisen on a number of client sites I am familiar
with.

I would like some assistance in testing and refining the module before
publishing it on CPAN. It has very basic functionality at the moment.

I also need to determine whether there are any TradeMark issues with
the name I am currently using for this module, more explicitly the
inclusion of the name/word Vignette therein.

If you have any suggestions on a name for the module and/or are able
to assist with the testing of this module, I would appreciate it.

Thank you.


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

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


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