[16298] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3710 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 18 09:32:59 2000

Date: Tue, 18 Jul 2000 06:32:39 -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: <963927158-v9-i3710@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 18 Jul 2000     Volume: 9 Number: 3710

Today's topics:
        communicating through the location bar (Raphael Pirker)
    Re: communicating through the location bar (Ecco)
    Re: communicating through the location bar (Keith Calvert Ivey)
    Re: communicating through the location bar (Ecco)
    Re: communicating through the location bar (Tony Curtis)
    Re: communicating through the location bar (Raphael Pirker)
    Re: communicating through the location bar (Steven Smolinski)
    Re: communicating through the location bar (Keith Calvert Ivey)
    Re: communicating through the location bar (Ecco)
    Re: communicating through the location bar (jason)
    Re: communicating through the location bar (Jonathan Stowe)
    Re: Comparing Two Files Problem ()
        Computing date + xxx days ()
    Re: Computing date + xxx days (Stephen Kloder)
    Re: Computing date + xxx days (jason)
    Re: Computing date + xxx days (Bob Walton)
    Re: Computing date + xxx days (Malcolm Ray)
    Re: Computing date + xxx days (jason)
        configuring perl on windows2000 <mm_@webzure.com>
    Re: Construct HTML page from a text file. (Craig Berry)
        context confusion (Dave McIntyre)
    Re: context confusion (Eric Bohlman)
    Re: context confusion (Jürgen Exner)
    Re: context confusion (Jakob Schmidt)
    Re: context confusion (Dave McIntyre)
    Re: context confusion (Abigail)
    Re: context confusion (Jakob Schmidt)
        convert file permissions; octal-->stat ()
    Re: convert file permissions; octal-->stat ()
    Re: convert file permissions; octal-->stat (Jonathan Stowe)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 16 Jul 2000 13:30:02 GMT
From: raphaelp@nr1webresource.com.bbs@openbazaar.net (Raphael Pirker)
Subject: communicating through the location bar
Message-Id: <3bQO4Q$VC3@openbazaar.net>

Hi,

I'm trying to make the script act according to the location that it is
called upon. For example:

preview.pl?form_type=feedback

gives the variable $form_type the value "feedback". Is this possible? Here's
what I've come up with so far:

#!/usr/bin/perl

# Create Forms Code

use CGI 'param';
$form_type=param('form_type');

$form_type_file1 = "forms/".$form_type."1.txt";
$form_type_file2 = "forms/".$form_type."2.txt";

$/ = undef;
open FILE, $form_type_file1;
$form_type_code1 = <FILE>;
close FILE;
$/ = "\n";

$/ = undef;
open FILE, $form_type_file2;
$form_type_code2 = <FILE>;
close FILE;
$/ = "\n";

print "Content-type: text/html\n\n";
print "<form>";
print "$form_type_code1";
print "$form_type_code2";
print "</form>";

exit;


Thanks in advance,

Raphael


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

Date: 16 Jul 2000 14:00:02 GMT
From: ecco64@chello.nl.bbs@openbazaar.net (Ecco)
Subject: Re: communicating through the location bar
Message-Id: <3bQOg3$VO2@openbazaar.net>

The way you use stores everything after the ? in the URL in the variable
$ENV{'QUERY_STRING'}
So when you use

preview.pl?form_type=feedback

you just need to split it up:

@array = SPLIT(/=/$ENV{'QUERY_STRING'});

now both "form-type" and "feedback" are stored in an array, you can work
with that.
Hope I was of any help, goodluck!

"Raphael Pirker" <raphaelp@nr1webresource.com> wrote in message
news:8ksde7$liq$18$1@news.t-online.com...
> Hi,
>
> I'm trying to make the script act according to the location that it is
> called upon. For example:
>
> preview.pl?form_type=feedback
>
> gives the variable $form_type the value "feedback". Is this possible?
Here's
> what I've come up with so far:
>
> #!/usr/bin/perl
>
> # Create Forms Code
>
> use CGI 'param';
> $form_type=param('form_type');
>
> $form_type_file1 = "forms/".$form_type."1.txt";
> $form_type_file2 = "forms/".$form_type."2.txt";
>
> $/ = undef;
> open FILE, $form_type_file1;
> $form_type_code1 = <FILE>;
> close FILE;
> $/ = "\n";
>
> $/ = undef;
> open FILE, $form_type_file2;
> $form_type_code2 = <FILE>;
> close FILE;
> $/ = "\n";
>
> print "Content-type: text/html\n\n";
> print "<form>";
> print "$form_type_code1";
> print "$form_type_code2";
> print "</form>";
>
> exit;
>
>
> Thanks in advance,
>
> Raphael
>
>


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

Date: 16 Jul 2000 15:20:02 GMT
From: kcivey@cpcug.org.bbs@openbazaar.net (Keith Calvert Ivey)
Subject: Re: communicating through the location bar
Message-Id: <3bQQk2$V0K@openbazaar.net>

"Ecco" <ecco64@chello.nl> wrote:

>preview.pl?form_type=feedback
>
>you just need to split it up:
>
>@array = SPLIT(/=/$ENV{'QUERY_STRING'});
>
>now both "form-type" and "feedback" are stored in an array, you can work
>with that.

He's already doing fine with that part.  No need to persuade him
to take a step backward and abandon CGI.pm in favor of some
buggy hand-coded solution.  Suppose the request ends like this:

    preview.pl?form_type=feedback&mode=create

Then how does your method help?  Just use CGI.pm (or some other
well-tested, supported module) -- it works.

--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
(Free at last from the forced spamsig of
Newsfeeds.com, cursed be their name)


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

Date: 16 Jul 2000 18:40:10 GMT
From: ecco64@chello.nl.bbs@openbazaar.net (Ecco)
Subject: Re: communicating through the location bar
Message-Id: <3bQW89$THi@openbazaar.net>

YOU USE SPLIT SMARTGUY

--
-----------------------------------------------------
Click here for Free Video!!
http://www.gohip.com/free_video/

"Keith Calvert Ivey" <kcivey@cpcug.org> wrote in message
news:397ac4bd.138685405@news.newsguy.com...
> "Ecco" <ecco64@chello.nl> wrote:
>
> >preview.pl?form_type=feedback
> >
> >you just need to split it up:
> >
> >@array = SPLIT(/=/$ENV{'QUERY_STRING'});
> >
> >now both "form-type" and "feedback" are stored in an array, you can work
> >with that.
>
> He's already doing fine with that part.  No need to persuade him
> to take a step backward and abandon CGI.pm in favor of some
> buggy hand-coded solution.  Suppose the request ends like this:
>
>     preview.pl?form_type=feedback&mode=create
>
> Then how does your method help?  Just use CGI.pm (or some other
> well-tested, supported module) -- it works.
>
> --
> Keith C. Ivey <kcivey@cpcug.org>
> Washington, DC
> (Free at last from the forced spamsig of
> Newsfeeds.com, cursed be their name)


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

Date: 16 Jul 2000 21:40:10 GMT
From: tony_curtis32@yahoo.com.bbs@openbazaar.net (Tony Curtis)
Subject: Re: communicating through the location bar
Message-Id: <3bQaf9$WrZ@openbazaar.net>

>> On Sun, 16 Jul 2000 23:23:20 +0200,
>> "Raphael Pirker" <raphaelp@nr1webresource.com> said:

> could someone please provide the code that I would use
> to make a variable called $form_type and it's respecting
> value the thing after the "=" sign.

  http://www.server/path/to/script?name=tony&sex=m

    script:

    use CGI ':standard';
    my $name = param('name');

See the documentation

  perldoc LWP
  perldoc HTTP::Request
  perldoc URI

for how to construct and make requests for URLs.

hth
t
--
"With $10,000, we'd be millionaires!"
                                           Homer Simpson


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

Date: 16 Jul 2000 21:30:13 GMT
From: raphaelp@nr1webresource.com.bbs@openbazaar.net (Raphael Pirker)
Subject: Re: communicating through the location bar
Message-Id: <3bQaSb$U0G@openbazaar.net>

> you just need to split it up:
>
> @array = SPLIT(/=/$ENV{'QUERY_STRING'});

could someone please provide the code that I would use to make a variable
called $form_type and it's respecting value the thing after the "=" sign.
I'm very unfamiliar with perl and don't know anything about it!


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

Date: 16 Jul 2000 23:20:01 GMT
From: sjs@yorku.ca.bbs@openbazaar.net (Steven Smolinski)
Subject: Re: communicating through the location bar
Message-Id: <3bQdM1$V00@openbazaar.net>

Ecco <ecco64@chello.nl> wrote:
>I gave you the code in my previous post; this is how split works:

[You really ought to quote who you are replying to so the rest of us may
follow along.]

>$Variable = "blabla=yada";
>
>#you want "blabla" and "yada" split up:
>
>@Array = SPLIT(/=/$Variable);
          ^^^^^    ^

This won't compile.  'SPLIT' is not a perl function.  'split' is.  Also,
your arguments to split must be seperated by a comma.

>#This splits up $Variable at the "=" sign.
>#Now both "blabla" and "yada" are stored in @Array
>
>print $Array[0],"\n";
>print $Array[1];
>
>this outputs:
>    blabla
>    yada

You obviously didn't test this.

There's also much more to split than meets the eye of this casual
observer.  Try perldoc -f split for something more complete.

Steve


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

Date: 16 Jul 2000 22:50:01 GMT
From: kcivey@cpcug.org.bbs@openbazaar.net (Keith Calvert Ivey)
Subject: Re: communicating through the location bar
Message-Id: <3bQcWP$Uu0@openbazaar.net>

"Raphael Pirker" <raphaelp@nr1webresource.com> wrote:

>could someone please provide the code that I would use to make a variable
>called $form_type and it's respecting value the thing after the "=" sign.
>I'm very unfamiliar with perl and don't know anything about it!

Could you explain exactly what problem you're having?  In your
previous message, you posted the code you're asking for above,
so you already have it.  Here it is, quoted from your message
(the one that started this thread):

:    use CGI 'param';
:    $form_type=param('form_type');

--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
(Free at last from the forced spamsig of
Newsfeeds.com, cursed be their name)


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

Date: 16 Jul 2000 23:10:01 GMT
From: ecco64@chello.nl.bbs@openbazaar.net (Ecco)
Subject: Re: communicating through the location bar
Message-Id: <3bQd9P$Tvk@openbazaar.net>

I gave you the code in my previous post; this is how split works:

$Variable = "blabla=yada";

#you want "blabla" and "yada" split up:

@Array = SPLIT(/=/$Variable);

#This splits up $Variable at the "=" sign.
#Now both "blabla" and "yada" are stored in @Array

print $Array[0],"\n";
print $Array[1];

this outputs:
    blabla
    yada


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

Date: 16 Jul 2000 23:20:02 GMT
From: elephant@squirrelgroup.com.bbs@openbazaar.net (jason)
Subject: Re: communicating through the location bar
Message-Id: <3bQdM4$VC5@openbazaar.net>

Ecco wrote ..
>I gave you the code in my previous post; this is how split works:
>
>$Variable = "blabla=yada";
>
>#you want "blabla" and "yada" split up:
>
>@Array = SPLIT(/=/$Variable);
>
>#This splits up $Variable at the "=" sign.
>#Now both "blabla" and "yada" are stored in @Array

it does no such thing .. the above produces the syntax error

  Scalar found where operator expected

and even if you fix up your missing comma .. SPLIT() is not a Perl
function .. split() is .. so

  @Array = SPLIT(/=/,$Variable);

produces the runtime error

  Undefined subroutine &main::SPLIT called

and even if you fix BOTH of those errors your code your post was
completely out of place .. the originator was already successfully using
the standard CGI module to retrieve the query values .. something that
you would do well to learn

(ie. the originator's code is far superior to your own split() solution
- stop trying to teach on this topic and begin learning)

--
  jason -- elephant@squirrelgroup.com --


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

Date: 17 Jul 2000 08:30:04 GMT
From: gellyfish@gellyfish.com.bbs@openbazaar.net (Jonathan Stowe)
Subject: Re: communicating through the location bar
Message-Id: <3bR5bS$UGS@openbazaar.net>

On Sun, 16 Jul 2000 18:46:33 GMT Ecco wrote:
> "Keith Calvert Ivey" <kcivey@cpcug.org> wrote in message
> news:397ac4bd.138685405@news.newsguy.com...
>> "Ecco" <ecco64@chello.nl> wrote:
>>
>> >preview.pl?form_type=feedback
>> >
>> >you just need to split it up:
>> >
>> >@array = SPLIT(/=/$ENV{'QUERY_STRING'});
>> >
>> >now both "form-type" and "feedback" are stored in an array, you can work
>> >with that.
>>
>> He's already doing fine with that part.  No need to persuade him
>> to take a step backward and abandon CGI.pm in favor of some
>> buggy hand-coded solution.  Suppose the request ends like this:
>>
>>     preview.pl?form_type=feedback&mode=create
>>
>> Then how does your method help?  Just use CGI.pm (or some other
>> well-tested, supported module) -- it works.
>>
>
> YOU USE SPLIT SMARTGUY
>

There appears to be something wrong with the caps lock on your computer.

The OP was doing just fine with CGI.pm and you wade in with a partial
solution that gets him no further than he already had got.


/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: 18 Jul 2000 02:10:02 GMT
From: RichardWoodward@hotmail.com.bbs@openbazaar.net ()
Subject: Re: Comparing Two Files Problem
Message-Id: <3bRXIQ$VK1@openbazaar.net>

Hello, Oleg.

Before you get too much further along with this
"pretty much first Perl script," please reconsider!

The problem is (probably) much more complicated than
you realize at this point.  Also, it has been solved
(lots of ways) by others.  Do a search on the web
for "diff utility". You should get a lot of hits.

PS I would not often want to use perl variables
of 1.7G myself.  If the programming language
and operating system haven't solved the efficiency
problem in dealing with large files, it will probably
be very hard for you to solve it (and in each and
every application which uses large files).

Regards,
Richard Martin Woodward
RichardWoodward@hotmail.com
==============================================
In article <smpm12b7nd6126@corp.supernews.com>,
  "Oleg Kuzmin" <kuzmin@hotmail.com> wrote:
> Greetings!
>
> I'm trying to write my pretty much first Perl script, and it
> doesn't work the way I want it to.
>
> Here is a beginning - very simple, opening "old" file to be
> compared with the "new" one.  The results of comparison will
> go to the "result" file.
> "New" and "old" files are huge ASCII files, ranging from 146M
> to 1.7G in size.
>
> ----------------------------------------
>  use Getopt::Long;

<snip>
 
 
 


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 17 Jul 2000 02:40:11 GMT
From: jhalbrook@my-deja.com.bbs@openbazaar.net ()
Subject: Computing date + xxx days
Message-Id: <3bQiWB$WHm@openbazaar.net>

I'm a newbie to Perl.

I was curious if there is a quick and dirty way to perform
simple date math?  I simply need to add xxx number of days
to a given Gregorian date, and produce the resulting date.

Any help is appreciated.

JH



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 17 Jul 2000 03:00:10 GMT
From: stephenk@cc.gatech.edu.bbs@openbazaar.net (Stephen Kloder)
Subject: Re: Computing date + xxx days
Message-Id: <3bQj9A$Xbl@openbazaar.net>

jhalbrook@my-deja.com wrote:

> I'm a newbie to Perl.
>
> I was curious if there is a quick and dirty way to perform
> simple date math?  I simply need to add xxx number of days
> to a given Gregorian date, and produce the resulting date.
>
> Any help is appreciated.
>
> JH

Take a look at the functions localtime (in perlfunc) and timelocal (in
Time::Local).

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.


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

Date: 17 Jul 2000 02:50:12 GMT
From: elephant@squirrelgroup.com.bbs@openbazaar.net (jason)
Subject: Re: Computing date + xxx days
Message-Id: <3bQiia$UDr@openbazaar.net>

jhalbrook@my-deja.com wrote ..
>I was curious if there is a quick and dirty way to perform
>simple date math?  I simply need to add xxx number of days
>to a given Gregorian date, and produce the resulting date.

  perldoc -f time
  perldoc -f localtime

you want something like

  @localtime = localtime( time + 24 * 3600 * $x );

where $x is the number of days you want added .. used in a scalar
context it will output a string .. the docs tell all

btw .. it's quick - but there's nothing dirty about it

--
  jason -- elephant@squirrelgroup.com --


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

Date: 17 Jul 2000 03:50:02 GMT
From: bwalton@rochester.rr.com.bbs@openbazaar.net (Bob Walton)
Subject: Re: Computing date + xxx days
Message-Id: <3bQkNQ$UGS@openbazaar.net>

jhalbrook@my-deja.com wrote:
 ...
> I was curious if there is a quick and dirty way to perform
> simple date math?  I simply need to add xxx number of days
> to a given Gregorian date, and produce the resulting date.
 ...
> JH
 ...
Take a look at the Date::Manip and Date::Calc modules.
--
Bob Walton


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

Date: 17 Jul 2000 15:30:02 GMT
From: M.Ray@ulcc.ac.uk.bbs@openbazaar.net (Malcolm Ray)
Subject: Re: Computing date + xxx days
Message-Id: <3bRGYQ$Vu6@openbazaar.net>

On Mon, 17 Jul 2000 02:50:32 GMT, jason <elephant@squirrelgroup.com> wrote:
>jhalbrook@my-deja.com wrote ..
>>I was curious if there is a quick and dirty way to perform
>>simple date math?  I simply need to add xxx number of days
>>to a given Gregorian date, and produce the resulting date.
>
>  perldoc -f time
>  perldoc -f localtime
>
>you want something like
>
>  @localtime = localtime( time + 24 * 3600 * $x );
>
>where $x is the number of days you want added .. used in a scalar
>context it will output a string .. the docs tell all
>
>btw .. it's quick - but there's nothing dirty about it

Beware: in many (most?) locales, not every day is 24 hours long.
Think of daylight saving time, and consider what can happen to the
above code when used during a 25-hour day.
--
Malcolm Ray                           University of London Computer Centre


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

Date: 17 Jul 2000 21:50:02 GMT
From: elephant@squirrelgroup.com.bbs@openbazaar.net (jason)
Subject: Re: Computing date + xxx days
Message-Id: <3bRQTR$XLZ@openbazaar.net>

Malcolm Ray wrote ..
>On Mon, 17 Jul 2000 02:50:32 GMT, jason <elephant@squirrelgroup.com> wrote:
>>jhalbrook@my-deja.com wrote ..
>>>I was curious if there is a quick and dirty way to perform
>>>simple date math?  I simply need to add xxx number of days
>>>to a given Gregorian date, and produce the resulting date.
>>
>>  perldoc -f time
>>  perldoc -f localtime
>>
>>you want something like
>>
>>  @localtime = localtime( time + 24 * 3600 * $x );
>>
>>where $x is the number of days you want added .. used in a scalar
>>context it will output a string .. the docs tell all
>>
>>btw .. it's quick - but there's nothing dirty about it
>
>Beware: in many (most?) locales, not every day is 24 hours long.
>Think of daylight saving time, and consider what can happen to the
>above code when used during a 25-hour day.

ok .. good point .. it is dirty after all

--
  jason -- elephant@squirrelgroup.com --


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

Date: Tue, 18 Jul 2000 10:57:54 GMT
From: "macromueslia" <mm_@webzure.com>
Subject: configuring perl on windows2000
Message-Id: <SKWc5.5234$4p3.38292@news-server.bigpond.net.au>

For some reason since installing the new version of ActivePerl for win32 my
scripts keep looking for data files in the C:\ directory. I have to type in
the full path to the cgi-bin now...eg:  $counter=
"/IIS/www/cgi-bin/counter.dat";

How do I get / to resole to the directory the script is running in?


--
Andrew Dresden




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

Date: 11 Jul 2000 20:00:04 GMT
From: cberry@cinenet.net.bbs@openbazaar.net (Craig Berry)
Subject: Re: Construct HTML page from a text file.
Message-Id: <3bMca6$W8A@openbazaar.net>

Ken H. Lee (kenhlee@tm.net.my) wrote:
: Hi,
:   I am tring to read from a text file and print the html page. The code is
: something like this:
:   print "HTTP 1.0 200 OK/n";
:   print "pragma: no-cache\n";
:   print "Content-type: text/html\n";
:   print "\n";

In general, the server will add the first line (if this is a CGI, that
is), and the others are more reliably and easily generated using the CGI
module.

:   $file = "nlplus.tpl";
:   open (IDFILE, $file);

Never ever ever ever ever...[117 repetitions omitted]...*ever* fail to
check the success of open.  Any number of weird things (permission
problems and cwd not being what you think it is being the big two) can
cause the open to fail; without a check, you'll have no clue why other
stuff is then acting funny.  At minimum,

  open IDFILE, $file or die $!;

See CGI::Carp for nice things like fatalsToBrowser which will put any
die() messages onto the generated page rather than just the log file.

:   print "<html>\n";
:   print "<body>\n";
:   print "<h1>test1 </h1>\n";
:
:   while (<IDFILE>)
:   {
:     $rec = $_;
:     print $rec;
:    }

Why go to all that trouble?  Either

  print while <IDFILE>;

or

  print <IDFILE>;

will work; the latter is inadvisable for large files, however.

:   print "<h1>test1 </h1>\n";
:  print "</body>";
:  print "</html>";
:
:  close (IDFILE);
:
: I can see the "test" line on my browser but not the contain inside the
: "while" loop.

I'll bet the open() is failing.

: When I try in DOS prompt : perl nlplus.pl, the correct html page can come
: out.

Especially with that further info.

: I am running NT 4.0 with IIS 3.0.

Sorry, that's a separate bug report. :)

--
   |   Craig Berry - http://www.cinenet.net/users/cberry/home.html
 --*--  "Beauty and strength, leaping laughter and delicious
   |   languor, force and fire, are of us." - Liber AL II:20


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

Date: 17 Jul 2000 20:50:03 GMT
From: dem@achilles.net.bbs@openbazaar.net (Dave McIntyre)
Subject: context confusion
Message-Id: <3bRP2T$XDX@openbazaar.net>

Hello c.l.p.misc. For the statement:

if ($val >= 1 && $val <= 99 ) { print "in range";}

could someone please tell me why (or where to look it up) it's printing if

$val="6A";  # or somesuch

Is there a better way to determine if $val is in range?


TIA,
Dave


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

Date: 17 Jul 2000 21:20:02 GMT
From: ebohlman@netcom.com.bbs@openbazaar.net (Eric Bohlman)
Subject: Re: context confusion
Message-Id: <3bRPe2$ULt@openbazaar.net>

Dave McIntyre (dem@achilles.net) wrote:
: Hello c.l.p.misc. For the statement:
:
: if ($val >= 1 && $val <= 99 ) { print "in range";}
:
: could someone please tell me why (or where to look it up) it's printing if
:
: $val="6A";  # or somesuch

You're getting bitten by Perl's string-to-number conversion rules.  If a
string begins with numeric characters (digits, minus sign, etc) it will
convert those to a number and ignore the rest of the string if the string
is being used in a numeric context (such as that imposed by the numeric
comparison operators).  Therefore, "6A" is treated as 6 for numeric
comparison purposes.

: Is there a better way to determine if $val is in range?

Make sure it's a number (see the FAQ for ways to do this) before using it
in a numeric comparison.


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

Date: 17 Jul 2000 21:20:02 GMT
From: juex@deja.com.bbs@openbazaar.net (Jürgen Exner)
Subject: Re: context confusion
Message-Id: <3bRPe4$UTn@openbazaar.net>

"Dave McIntyre" <dem@achilles.net> wrote in message
news:8kvrhg$guq$1@bcarh8ab.ca.nortel.com...
> Hello c.l.p.misc. For the statement:
>
> if ($val >= 1 && $val <= 99 ) { print "in range";}
>
> could someone please tell me why (or where to look it up) it's printing if
>
> $val="6A";  # or somesuch

Quite simple: 6 is greater-equal 1 and 6 is less-equal 99, therefore the
condition is true.
Maybe you forgot that "6" is returned as the numerical value of the string
"6A"?

> Is there a better way to determine if $val is in range?

What's wrong with your version?

jue


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

Date: 17 Jul 2000 22:00:02 GMT
From: sumus@aut.dk.bbs@openbazaar.net (Jakob Schmidt)
Subject: Re: context confusion
Message-Id: <3bRQg4$TLd@openbazaar.net>

"Dave McIntyre" <dem@achilles.net> writes:

> if ($val >= 1 && $val <= 99 ) { print "in range";}
>
> could someone please tell me why (or where to look it up) it's printing if
>
> $val="6A";  # or somesuch

Whaddaya mean "it's printing"? It isn't on my machine.

The operators <= and >= expect numbers. "A6" is zero to them. I'm not
really sure why it's not 6 like it is to int(), but there it is.

> Is there a better way to determine if $val is in range?

In my opinion the condition is OK in itself but if your using $val in that
context and it contains something that isn't a number then some part of
your code isn't OK. If you allow yourself to put salt in the sugar bin
you may get salty coffee at some point.

Unless you drink coffee without sugar. In that case try arsenik in the
flour bag in stead.

--
Jakob


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

Date: 17 Jul 2000 21:50:02 GMT
From: dem@achilles.net.bbs@openbazaar.net (Dave McIntyre)
Subject: Re: context confusion
Message-Id: <3bRQTS$XPY@openbazaar.net>

"Eric Bohlman" <ebohlman@netcom.com> wrote in message
news:8kvtcd$trq$4@slb0.atl.mindspring.net...
> Make sure it's a number (see the FAQ for ways to do this) before using it
> in a numeric comparison.

Great, found it in perlfaq4. Thanks, Eric and Jurgen.
Dave


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

Date: 17 Jul 2000 22:40:03 GMT
From: abigail@delanet.com.bbs@openbazaar.net (Abigail)
Subject: Re: context confusion
Message-Id: <3bRRi4$U9o@openbazaar.net>

Dave McIntyre (dem@achilles.net) wrote on MMDXII September MCMXCIII in
<URL:news:8kvrhg$guq$1@bcarh8ab.ca.nortel.com>:
?? Hello c.l.p.misc. For the statement:
??
?? if ($val >= 1 && $val <= 99 ) { print "in range";}
??
?? could someone please tell me why (or where to look it up) it's printing if
??
?? $val="6A";  # or somesuch
??
?? Is there a better way to determine if $val is in range?


You are comparing $val against a number. Hence, perl will treat $val
as a number, or else what you are doing doesn't make sense.

Now, which number should "6A" be? The obvious answer is 6. And in the
Perl universe, 6 happens to be larger than 1, and less than 99.

Of course, had you run with -w, Perl would have told you what was going on....


Always, Always, and I mean *****ALWAYS***** run with -w.


Abigail
--
sub A::TIESCALAR{bless\my$x=>A};package B;@q[0..3]=qw/Hacker Perl
Another Just/;use overload'""'=>sub{pop @q};sub A::FETCH{bless\my
$y=>B}; tie my $shoe => qq 'A';print "$shoe $shoe $shoe $shoe\n";


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

Date: 17 Jul 2000 22:30:03 GMT
From: sumus@aut.dk.bbs@openbazaar.net (Jakob Schmidt)
Subject: Re: context confusion
Message-Id: <3bRRVS$TTZ@openbazaar.net>

Jakob Schmidt <sumus@aut.dk> writes:

> "Dave McIntyre" <dem@achilles.net> writes:
>
> > $val="6A";  # or somesuch
>
> Whaddaya mean "it's printing"? It isn't on my machine.

Sorry about this part - i read "A6" where you wrote "6A". Others have
explained the difference.

--
Jakob


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

Date: 17 Jul 2000 16:00:02 GMT
From: ogiven@vertex.ucls.uchicago.edu.bbs@openbazaar.net ()
Subject: convert file permissions; octal-->stat
Message-Id: <3bRHO2$U4N@openbazaar.net>

I'm grabbing the permission info on a remote file via Net::FTP's dir
command.......then parsing the -rwxrwxrwx entry into octal form.  BUT i
then need to convert the octal num into the kind of num that stat
returns when it gives you a file mode, so that i can chmod the local
file from within my Perl script.

i know a bit shift sequence to convert file perms from the stat format
to octal (@modelist = (($mode&0700)>>6, ($mode&0070), ($mode&0007));),
but i don't know how to do the opposite: convert a file perm from octal
to the stat representation.........

can anyone suggest a way?
OR, since my knowledge of "bits" and such is sorely lacking, can anyone
point me to some documentation on the subject.  i've done a lot of
search engine/usenet querying, but i'm not turning up anything
relevant....

thanks,

Olivia


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 17 Jul 2000 22:10:01 GMT
From: mercma@my-deja.com.bbs@openbazaar.net ()
Subject: Re: convert file permissions; octal-->stat
Message-Id: <3bRR6P$Trr@openbazaar.net>

Hello,

I am not sure if this is exactly what you are looking for but you can
give it a try.

#!/usr/bin/perl


$file = shift;
($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($file);

print "$mode\n";
printf "%o\n",$mode;           # print $mode in octal
$oct = sprintf "%o\n",$mode;   # make $oct the octal of $mode
$mode2 = oct $oct;             # make $mode2 the decimal of $oct
print "$mode2\n";

Mike

In article <8kva1m$t0s$1@nnrp1.deja.com>,
  ogiven@vertex.ucls.uchicago.edu wrote:
> I'm grabbing the permission info on a remote file via Net::FTP's dir
> command.......then parsing the -rwxrwxrwx entry into octal form.  BUT
i
> then need to convert the octal num into the kind of num that stat
> returns when it gives you a file mode, so that i can chmod the local
> file from within my Perl script.
>
> i know a bit shift sequence to convert file perms from the stat format
> to octal (@modelist = (($mode&0700)>>6, ($mode&0070), ($mode&0007));),
> but i don't know how to do the opposite: convert a file perm from
octal
> to the stat representation.........
>
> can anyone suggest a way?
> OR, since my knowledge of "bits" and such is sorely lacking, can
anyone
> point me to some documentation on the subject.  i've done a lot of
> search engine/usenet querying, but i'm not turning up anything
> relevant....
>
> thanks,
>
> Olivia
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 18 Jul 2000 08:00:11 GMT
From: gellyfish@gellyfish.com.bbs@openbazaar.net (Jonathan Stowe)
Subject: Re: convert file permissions; octal-->stat
Message-Id: <3bRgOC$UqH@openbazaar.net>

[ Removed the long defunct comp.lang.perl ]

In comp.lang.perl.misc ogiven@vertex.ucls.uchicago.edu wrote:
> I'm grabbing the permission info on a remote file via Net::FTP's dir
> command.......then parsing the -rwxrwxrwx entry into octal form.  BUT i
> then need to convert the octal num into the kind of num that stat
> returns when it gives you a file mode, so that i can chmod the local
> file from within my Perl script.
>
> i know a bit shift sequence to convert file perms from the stat format
> to octal (@modelist = (($mode&0700)>>6, ($mode&0070), ($mode&0007));),
> but i don't know how to do the opposite: convert a file perm from octal
> to the stat representation.........
>
> can anyone suggest a way?
> OR, since my knowledge of "bits" and such is sorely lacking, can anyone
> point me to some documentation on the subject.  i've done a lot of
> search engine/usenet querying, but i'm not turning up anything
> relevant....
>

I misread your question the first time round as you having problems parsing
the output of ls -l into octal so I hacked together this brute force
method :


#!/usr/bin/perl -w

use strict;

my @files = map { chomp; [ unpack 'A11A4A9A9A9A13A*',$_ ]; } `ls -l`;

foreach (@files)
{
  my ( $mode, $file) = @{$_}[0,6];

  my $octmode = '0';

  foreach my $ugo ( $mode =~ /^.(.{3})(.{3})(.{3})/ )
  {
    my $thismode = 0;
    $ugo =~ /r/ && ($thismode += 4);
    $ugo =~ /w/ && ($thismode += 2);
    $ugo =~ /x/ && ($thismode += 1);
    $octmode .= $thismode;
  }
 print "$file $mode", oct $octmode,"\n";
}

It doesnt deal with setuid or setgid file though.  I think the answer to
your question is simply 'oct' though ...

/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
   <http://www.yapc.org/Europe/>   <http://www.ica.org.uk>


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3710
**************************************


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