[10684] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4276 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 22 22:07:21 1998

Date: Sun, 22 Nov 98 19:00:16 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 22 Nov 1998     Volume: 8 Number: 4276

Today's topics:
    Re: chmod (M.J.T. Guy)
    Re: detecting hard drives (Jye Tucker)
    Re: detecting hard drives (Jye Tucker)
        File handels to a variable <toto@javanet.com>
        HELP!!!!! <eric@egdc.net>
    Re: HTTP_REFERER and Browser History <flavell@mail.cern.ch>
    Re: Mastering Regular Expressions (was Re: Recommend Pe <uri@sysarch.com>
    Re: Matching Text Outside HTML Tags <r_larsen@image.dk>
    Re: pod2man and Y2K <Russell_Schulz@locutus.ofB.ORG>
        problem using CGI redirect() and cookie()? <dtbaker-@busprod.com>
    Re: Regular expression problem... <uri@sysarch.com>
    Re: Regular expression problem... <dgris@moiraine.dimensional.com>
    Re: Regular expression problem... <uri@sysarch.com>
    Re: Rounding dollar values (Larry Rosler)
    Re: Sorting a flat file <r28629@email.sps.mot.com>
        supressing output from external program in perl <kwood@music.unt.edu>
    Re: supressing output from external program in perl (Martien Verbruggen)
        UPDATE! HELP!!!! <eric@egdc.net>
    Re: UPDATE! HELP!!!! (Martien Verbruggen)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 23 Nov 1998 00:09:14 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: chmod
Message-Id: <73a93a$p5a$1@pegasus.csx.cam.ac.uk>

Peter J. Kernan <pete@theory2.phys.cwru.edu> wrote:
>With parens you provide a list context.

Wrong.   Usually, parens have no effect on context.

( There are a couple of special cases  -  the lhs of an assignment and
  the lhs of the 'x' operator.   But they're the exception, not the rule. )


Mike Guy


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

Date: Mon, 23 Nov 1998 10:52:52 +1000
From: jye@buckconsultants.com.au (Jye Tucker)
Subject: Re: detecting hard drives
Message-Id: <jye-ya02408000R2311981052520001@qld.nnrp.telstra.net>

In article <737hpq$1bd$1@news0-alterdial.uu.net>,
gward@thrak.cnri.reston.va.us (Greg Ward) wrote:

> On Fri, 20 Nov 1998, Jye Tucker <jye@buckconsultants.com.au> wrote:
> >What I am trying to do is to ask the script to detect what hard drives are
> >connected to the machine so that I can use the mount system command to
> >mount them. 
> >
> >Has anyone heard of any modules or techniques for detecting hardware or am
> >I just going to have to grep through the output of dmesg?
> 
> Whatever you do, it will probably be very unportable -- there just isn't
> a standard way of doing this.  Depending on FreeBSD's capabilities,
> there might be nicer alternatives.  If it has something like Linux'
> /proc filesystem, perhaps the information you need is in there
> (somehow).  Or you could make an a priori list of "all possible" drives
> in a PC system (eg. under Linux I'd start with /dev/hd[abcd] (for four
> IDE disks -- since you're just looking for disks, partitioning doesn't
> matter) and /dev/sd[abcdefg] (seven SCSI disks).  Then try to read a
> sector from each one in turn.  Again under Linux, I get chunks of
> gibberish from /dev/hda and /dev/hdc (my hard disk and CD-ROM) and
> "Device not configured" errors from /dev/hd[bd] and /dev/sd? -- because 
> I have no SCSI devices and no other IDE devices.  You might have to
> worry about long timeouts though -- I suppose you could fork a
> sub-process for each 'poke' and kill 'em if they don't respond back
> within x seconds.
> 
> Of course, this only detects IDE and SCSI devices, it doesn't tell you
> which are hard disks and which are CD-ROM drives, tape drives, etc.
> That's left as an exercise for the reader (meaning I'm clueless).

I totally agree that it will be VERY unportable. The suggestion of creating
a list of all possible drives and testing each one individually was another
option. That way I can check for partitions by doing a recursive search on
each 
drive until a partition doesn't respond to it's 'poke' :)

Most of the systems I'm dealing with will either be using IDE or SCSI
drives so doing it like this shouldn't be too involved.

I think that could be the way to go. Thanks Greg.

Jye


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

Date: Mon, 23 Nov 1998 11:00:40 +1000
From: jye@buckconsultants.com.au (Jye Tucker)
Subject: Re: detecting hard drives
Message-Id: <jye-ya02408000R2311981100400001@qld.nnrp.telstra.net>

In article <7396da$1a2$1@gellyfish.btinternet.com>, Jonathan Stowe
<gellyfish@btinternet.com> wrote:

> On Fri, 20 Nov 1998 13:59:21 +1000 Jye Tucker
<jye@buckconsultants.com.au> wrote:
> > Hi there,
> > 
> > I'm trying to write a perl script to be put onto a FreeBSD boot floppy and
> > used in a number of different machines with no guarantees of consistant
> > hardware. 
> > 
> 
> Are you sure you're going to get Perl onto a boot floppy ?
> 
> > What I am trying to do is to ask the script to detect what hard drives are
> > connected to the machine so that I can use the mount system command to
> > mount them. 
> > 
> > Has anyone heard of any modules or techniques for detecting hardware or am
> > I just going to have to grep through the output of dmesg?
> > 
> Actually I dont think even grepping dmesg is going to help because that is
> only going to tell you what physical drives are present and not the
> indiviadual filesystems therein.

Hi Jonathan,

Thanks for your reply. At least if I grep dmesg and find the physical
drives, it'll take less time to find the slices by Greg's "poking"
suggestion and a nice while loop which searches for slices on each hard
drive.

Thanks,

Jye


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

Date: Sun, 22 Nov 1998 19:37:11 -0500
From: "Josh Feinblum" <toto@javanet.com>
Subject: File handels to a variable
Message-Id: <73aa64$ee6$1@as4100c.javanet.com>

I asked a question earlier about a writing a filehandle to a variable.

The response was to use the module IO::Scalar.  This worked, but had an
undesired side effect.

Part of the difficulty is that some of the print statements need to go to a
file.  Is there anyway to re-direct a specific filehandle to a variable?
>From my research I beleive that on solution would be setvbuf but I can't
seem to get it to work right.

Thanks in advance
Josh






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

Date: Sun, 22 Nov 1998 19:50:27 +0000
From: Eric Gessner <eric@egdc.net>
Subject: HELP!!!!!
Message-Id: <36586A8D.2FE17CA8@egdc.net>

This is a multi-part message in MIME format.
--------------3BED32699D903FDDD4B53373
Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353"
Content-Transfer-Encoding: 7bit

the script below works with any HTML form.  it displays what the HTML
forms NAME(keys) and VALUES are.  my problem is.  my form consists of
several different NAMES like,

"car_Premium Sound Pkg. I"
"car_Premium Sound Pkg. II"
"car_Security system upgrade"

some of the other fields have generic names.  putting the "car_" in
front of certain fields allows me to search for these and return them
into a list.  that's my problem.  how do i get them into a list?

also, each of the above categories have a number VALUE assigned. Like,

"car_Premium Sound Pkg. I" -- 370
"car_Premium Sound Pkg. II" -- 590
"car_Security system upgrade" -- 200

How do i throw these VALUES into a list or an array, and make them add
themselves up?  This total would then be added to one other number and
that would equal the grand total.

Thanks a bunch to whomever can help me!!!
eric


----------------------------------------------------------
#!/usr/bin/perl

%cgivars= &getcgivars ;

print "Content-type: text/html\n\n" ;
print <<EOF ;
<html>
<head><title>CGI Results</title></head>
<body>
<h1>Hello, world.</h1>
Your CGI input variables were:
<ul>
EOF

#   though the &getcgivars() routine correctly handles similarly named
#   fields-- it delimits the multiple values with the \0 character,
within
#   $cgivars{$_}.
foreach (keys %cgivars) {
    print "<br>$_ = $cgivars{$_}\n" ;
}

# Print close of HTML file
print <<EOF ;
</ul>
</body>
</html>
EOF

exit ;

#----------------- start of &getcgivars() module ----------------------

# Read all CGI vars into an associative array.
# If multiple input fields have the same name, they are concatenated
into
#   one array element and delimited with the \0 character (which fails
if
#   the input has any \0 characters, very unlikely but conceivably
possible).
# Currently only supports Content-Type of
application/x-www-form-urlencoded.
sub getcgivars {
    local($in, %in) ;
    local($name, $value) ;


    # First, read entire string of CGI vars into $in
    if ( ($ENV{'REQUEST_METHOD'} eq 'GET') ||
         ($ENV{'REQUEST_METHOD'} eq 'HEAD') ) {
        $in= $ENV{'QUERY_STRING'} ;

    } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
        if ($ENV{'CONTENT_TYPE'}=~
m#^application/x-www-form-urlencoded$#i) {
            $ENV{'CONTENT_LENGTH'}
                || &HTMLdie("No Content-Length sent with the POST
request.") ;
            read(STDIN, $in, $ENV{'CONTENT_LENGTH'}) ;

        } else {
            &HTMLdie("Unsupported Content-Type: $ENV{'CONTENT_TYPE'}") ;

        }

    } else {
        &HTMLdie("Script was called with unsupported REQUEST_METHOD.") ;

    }

    # Resolve and unencode name/value pairs into %in
    foreach (split('&', $in)) {
        s/\+/ /g ;
        ($name, $value)= split('=', $_, 2) ;
        $name=~ s/%(..)/chr(hex($1))/ge ;
        $value=~ s/%(..)/chr(hex($1))/ge ;
        $in{$name}.= "\0" if defined($in{$name}) ;  # concatenate
multiple vars
        $in{$name}.= $value ;
    }

    return %in ;

}


# Die, outputting HTML error page
# If no $title, use a default title
sub HTMLdie {
    local($msg,$title)= @_ ;
    $title || ($title= "CGI Error") ;
    print <<EOF ;
Content-type: text/html

<html>
<head>
<title>$title</title>
</head>
<body>
<h1>$title</h1>
<h3>$msg</h3>
</body>
</html>
EOF

    exit ;
}


--------------3BED32699D903FDDD4B53373
Content-Type: text/x-vcard; charset=us-ascii;
 name="eric.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Eric Gessner
Content-Disposition: attachment;
 filename="eric.vcf"

begin:vcard 
n:Gessner;Eric
tel;fax:717-522-9202
tel;home:717-523-1705
tel;work:717-522-9200
x-mozilla-html:TRUE
url:http://www.egdc.net
org:EGDC.net
adr:;;P.O. Box 5;Lewisburg;PA;17837;USA
version:2.1
email;internet:eric@egdc.net
title:Web Site/Multimedia Developer
note:ICQ# - 6331962
x-mozilla-cpt:;3
fn:Eric Gessner
end:vcard

--------------3BED32699D903FDDD4B53373--



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

Date: Mon, 23 Nov 1998 00:47:18 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: HTTP_REFERER and Browser History
Message-Id: <Pine.HPP.3.95a.981123004555.11142E-100000@hpplus01.cern.ch>

On Sun, 22 Nov 1998, Martien Verbruggen wrote:

> In article <365751B6.23AF1FD3@clockwork.net>,
> 	Dan Brian <dan@clockwork.net> writes:

(something we'd better draw a veil over)

> You didn't only post irrelevant and off-topic material to clp.misc,
> but it is also incorrect.

The two normally go together, don't you find?  

-- 

             "Auf dem entsprechenden Terminal schon." - 'Naddy' Weisgerber




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

Date: 22 Nov 1998 20:12:08 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Mastering Regular Expressions (was Re: Recommend Perl books?)
Message-Id: <x7k90n1ac7.fsf@sysarch.com>

>>>>> "IZ" == Ilya Zakharevich <ilya@math.ohio-state.edu> writes:

  IZ> I think most things *are* wrong now.  (Except the simplest ones, which
  IZ> one should not bother to look into any book for.)

i beg to differ. you are the leading developer and exponent of new regex
features and are likely to think this. what you think of as simple regex
stuff many think of as tricky. most of perl's commonly used regex
features are covered in depth. check out page 201 for the overview
table. it even refers to 5.002. so for the great majority of perl users
and most hackers it covers the regex stuff we need. and it explains the
guts and logic of using the main features better than any other text
(printed or online) anywhere.

  IZ> The book is still great as an educational tool, but any perl-specific
  IZ> statement should be carefully checked against the documentation.
  IZ> Especially those things which address problems of Perl's RExen, but
  IZ> many other too.  All the benchmarks are meaningless now.

i agree that specific details of bleeding edge features are not covered
but anyone who knows about them would know enough to check the online
docs.

  IZ> This is my impression only, I did not try to comb through this chapter
  IZ> with a highlight-pen and mark things are still-valid/invalid.

do it and i bet friedl would appreciate it for the 2nd edition (hint,
hint).

on the whole i think it is still to be recommended for its breadth and
depth of regex coverage. learning how regexes work internally and the
various ways to use all the features is what most people need to
learn. bleeding edge features they can pick up on their own as they
learn about their existance.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Sun, 22 Nov 1998 20:05:58 +0100
From: R. A. Larsen <r_larsen@image.dk>
Subject: Re: Matching Text Outside HTML Tags
Message-Id: <VA.0000008b.0045cd3a@octo>

dodadnau@my-dejanews.com wrote:
[cut]

Greg, why are you making a reply to a posting with another subject instead of 
starting a new thread? If I had killed the thread I would not have seen YOUR 
posting.

Reni
-- 
Using Virtual Access
http://www.vamail.com



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

Date: Sun, 22 Nov 1998 19:16:18 -0500
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: Re: pod2man and Y2K
Message-Id: <19981122.191618.7a1.rnr.w164w@locutus.ofB.ORG>

terra@diku.dk (Morten Welinder) writes:

> Is it just me, or is the pod2man converter broken?  It contain this
> code, that will invent "Year 100" in about 400 days.

it MUST be you.  nobody with > 1/2 a brain would use localtime()
without remembering the section of the C runtime specification
that mentioned that the year returned is really year-1900.

or at least, this is what I've read in c.l.perl.misc .

> (Please CC responses. ...

the new `Mail-Copies-To: poster' would do that automatically, on
actively-maintained newsreaders.  I'd do it, but I don't think you
were looking for such overly sarcastic responses too.
-- 
Russell_Schulz@locutus.ofB.ORG  Shad 86c


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

Date: Sun, 22 Nov 1998 18:30:55 -0600
From: Dan Baker <dtbaker-@busprod.com>
Subject: problem using CGI redirect() and cookie()?
Message-Id: <3658ACBF.6C6DB113@busprod.com>

I'm just starting with cookies today, and having trouble with
redirect(). I have been able to construct a cookie, and save it with the
header() function, but not when using redirect(). I don't want to use
header
because I want to go display an existing confirmation page for
instance... I can also make it work if I replace the header() call with
a plain 
print "Set-cookie: name=value";
but then can't get the value to change if I follow with a 
print "Location: http://localhost...";

Or, is there a way to redirct to a different script and pass along all
the form variables that may have gotten sent? Am I missing something
basic?

#! /usr/bin/perl -w

my $DirPath = 'hardcoded test path' ;

use CGI qw(cookie header redirect);

# set cookie
$PackedCookie = cookie( - NAME  => "WorkDir",
                        - VALUE => "$DirPath" );

# save cookie results
if ( 1 ){ # hardcode which method to use
        print header( - COOKIE => $PackedCookie );
        print "\nusing header, PackedCookie = $PackedCookie\n";
        print "works fine... Use browser back button...\n"
} else { 
        print redirect( 
        - URI           =>
'http://localhost/test/substitute/StartForm.htm',
        - COOKIE        => $PackedCookie );
}

__END__


-- 
Thanx, Dan

# If you would like to reply-to directly, remove the - from my username
* no spam please... regulated by US Code Title 47, Sec.227(a)(2)(B)  *


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

Date: 22 Nov 1998 20:17:11 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Regular expression problem...
Message-Id: <x7g1bb1a3s.fsf@sysarch.com>

>>>>> "IZ" == Ilya Zakharevich <ilya@math.ohio-state.edu> writes:

  IZ> I recall that one of my `use pedantic' or `use strict code' proposals
  IZ> is to make such ambiguities a fatal error.

are they going in to any soon to be released versions? if only scalars
are allowed in regexes (a reasonable restriction IMO) then you would not
have many ambiguities. all you have to do is assign the complex value
(HOH, LOL etc.) to a scalar before using it in the regex. the fact that
those expressions are valid in double quotish strings doesn't mean they
should be allowed in regexes where they can be parsed ambiguiosly.

this is one of those newbie traps. i would never use such complex values
in regexes directly. it is against my style.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 22 Nov 1998 18:45:40 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Regular expression problem...
Message-Id: <m3zp9jfagr.fsf@moiraine.dimensional.com>

Uri Guttman <uri@sysarch.com> writes:

> >>>>> "DG" == Daniel Grisinger <dgris@moiraine.dimensional.com> writes:

>   DG>   DB<1> $a = 'this is a test'
>
>   DG>   DB<2> $foo{foo}{foo} = '(?:\w+\s+)'
> 
>   DG>   DB<3> print qq.yup. if $a =~ /$foo{foo}{foo}{2}/
>   DG> yup

> this looks confusing. i tried a variant on yours:

It is, I was confused.  My example wasn't doing at all what 
I thought it was doing.

I thought that it was checking for exactly two occurences of
the pattern (?:\w+\s+) in the string `this is a test'.  What
it is actually doing is matching the null string in `this is 
a test'.

For example-

$ perl -Mre=debug -e '
       $a            = q.a.; 
       $b {foo}{foo} = q.b.;
       
       print qq.yup\n. if $a =~ /$b{foo}{foo}{2}/'
Omitting $` $& $' support.

EXECUTING...

compiling RE `'
size 2 first at 1
   1: NOTHING(2)
   2: END(0)
minlen 0 
Matching `' against `a'
  Setting an EVAL scope, savestack=3
   0 <> <a>               |  1:  NOTHING
   0 <> <a>               |  2:  END
yup
$ 

It appears to me that perl is seeing an uninitialized variable,
$b{foo}{foo}{2}, and interpolating the null string in its place.

> this area should be documented better. better yet, don't write regexes
> that look like that! it is bad coding to use arrays and hashes where you
> could find char classes and count modifiers.

Unless, of course, you are generating big regexes at runtime.
Then its nice to be able to qr// them and store them in a
giant hash.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
Supporter of grumpiness where grumpiness is due on clpm.
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: 22 Nov 1998 21:01:43 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Regular expression problem...
Message-Id: <x790h3181k.fsf@sysarch.com>

>>>>> "DG" == Daniel Grisinger <dgris@moiraine.dimensional.com> writes:

  DG> Uri Guttman <uri@sysarch.com> writes:


  DG> It appears to me that perl is seeing an uninitialized variable,
  DG> $b{foo}{foo}{2}, and interpolating the null string in its place.

i think it was executing the null regex as in page 70 of camel. this
would execute the last successful regex. my test seems to point in this
direction.

by using parens to disambiguate it you should be able to do what you
thought you tried:

	/(?:$b{foo}{foo}){2}/

but that defeats the whole ambiguity issue!

  >> this area should be documented better. better yet, don't write regexes
  >> that look like that! it is bad coding to use arrays and hashes where you
  >> could find char classes and count modifiers.

  DG> Unless, of course, you are generating big regexes at runtime.
  DG> Then its nice to be able to qr// them and store them in a
  DG> giant hash.

then you would just have a single real expression that won't be
undef, so it should be fine.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Sun, 22 Nov 1998 18:42:07 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Rounding dollar values
Message-Id: <MPG.10c26b5ee469a7ff98991d@nntp.hpl.hp.com>

In article <365860c9.165158958@news.cadvision.com> on Sun, 22 Nov 1998 
19:09:15 GMT, Scott Thompson <scotty@nospam.internetbrokers.ab.ca> 
says...
> What's the easiest way to round up results of a calculation, and limit
> it to 2 decimal places?

The two answers posted thus far, which glibly refer you to perlfaq4, 
have missed the key point in your question.  This is much more 
complicated than simply saying "use sprintf".

Firstly, let me quote the key paragraph from that FAQ:

"Rounding in financial applications can have serious implications, and 
the rounding method used should be specified precisely. In these cases, 
it probably pays not to trust whichever system rounding is being used by 
Perl, but to instead implement the rounding function you need yourself."

Now, let's look again at your request.  The 'sprintf' function referred 
to in the FAQ simply rounds to the nearest value, while you 
explicitly want to 'round up'.  I interpret that to mean that even the 
smallest fraction of a cent should be rounded up to the next higher 
cent.

Rather than use sprintf, I would 'implement the rounding function you 
need yourself':

$x *= 100;
$x = (($x != int $x) + int $x) / 100;

That is, I believe, the minimal-punctuation way of writing it, though 
perhaps not the most intuitive. :-)  It is slightly harder if $x is 
negative, but it's not explicit which way you want to 'round up' in that 
case -- magnitude or value.

General (not only Perl) programming footnote:  Financial computations in 
centimal currencies (dollars or pounds, for example) are best handled in 
integral cents or pence, and divided by 100 at the very end.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sun, 22 Nov 1998 19:36:02 -0500
From: Tk Soh <r28629@email.sps.mot.com>
To: shienh gurpreet <gss2@roogna.eng.wayne.edu>
Subject: Re: Sorting a flat file
Message-Id: <3658ADF1.416438D1@email.sps.mot.com>

[posted to c.l.p.m and copy emailed]

shienh gurpreet wrote:
> 
> Hello!!
> I tried looking at the perl FAQ but couldn't figure out how they were
> sorting the array with respect to any field. Here's the example database
> file I have, and I wanna sort it w.r.t. the 5th column (with %) in
> ascending order. Can someone please help as you have done before. Thank
> you.

Not trying to be mean, but do you really have tried, honest? 'perldoc -q sort'
brought up the faq almost instantaneously, unless you are on other system that
do not accept this command.

BTW, you question is irrelevant to comp.lang.perl.modules. I suppose you can
tell from the its name.

-TK


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

Date: Sun, 22 Nov 1998 20:12:30 -0600
From: Kelly Wood <kwood@music.unt.edu>
Subject: supressing output from external program in perl
Message-Id: <3658C48D.A4270D8@music.unt.edu>

Hello,

I'm new to perl, so please bear with me.  I'm using perl as a front end
to a sound synthesis
program called csound (this is in unix by the way) by using the exec
function:

exec("csound -d -m 0 -A devaudio -b256 -B4096 $choice.orc $choice.sco");

Perl executes csound which plays the audio, but my perl program waits
until csound has finished before going on.  Is there a way to tell perl
not to wait for csound's completion?

Thanks,
Kelly Wood
kwood@music.unt.edu



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

Date: Mon, 23 Nov 1998 02:14:19 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: supressing output from external program in perl
Message-Id: <%x362.95$wg2.221@nsw.nnrp.telstra.net>

In article <3658C48D.A4270D8@music.unt.edu>,
	Kelly Wood <kwood@music.unt.edu> writes:

> Perl executes csound which plays the audio, but my perl program waits
> until csound has finished before going on.  Is there a way to tell perl
> not to wait for csound's completion?

Euhmmm.. How does this relate to the subject of the post?

Anyway, look into fork:

# perldoc -f fork
# perldoc perlipc

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | The gene pool could use a little
Commercial Dynamics Pty. Ltd.       | chlorine.
NSW, Australia                      | 


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

Date: Sun, 22 Nov 1998 20:04:22 +0000
From: Eric Gessner <eric@egdc.net>
Subject: UPDATE! HELP!!!!
Message-Id: <36586DCE.253D440D@egdc.net>

This is a multi-part message in MIME format.
--------------C9B112D35A92F0CEDA3BAEA4
Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353"
Content-Transfer-Encoding: 7bit

Also, after I get the below names into a list or an array, how do i chop
off the "car_"?

===============================================
the script below works with any HTML form.  it displays what the HTML
forms NAME(keys) and VALUES are.  my problem is.  my form consists of
several different NAMES like,

"car_Premium Sound Pkg. I"
"car_Premium Sound Pkg. II"
"car_Security system upgrade"

some of the other fields have generic names.  putting the "car_" in
front of certain fields allows me to search for these and return them
into a list.  that's my problem.  how do i get them into a list?

also, each of the above categories have a number VALUE assigned. Like,

"car_Premium Sound Pkg. I" -- 370
"car_Premium Sound Pkg. II" -- 590
"car_Security system upgrade" -- 200

How do i throw these VALUES into a list or an array, and make them add
themselves up?  This total would then be added to one other number and
that would equal the grand total.

Thanks a bunch to whomever can help me!!!
eric


----------------------------------------------------------
#!/usr/bin/perl

%cgivars= &getcgivars ;

print "Content-type: text/html\n\n" ;
print <<EOF ;
<html>
<head><title>CGI Results</title></head>
<body>
<h1>Hello, world.</h1>
Your CGI input variables were:
<ul>
EOF

#   though the &getcgivars() routine correctly handles similarly named
#   fields-- it delimits the multiple values with the \0 character,
within
#   $cgivars{$_}.
foreach (keys %cgivars) {
    print "<br>$_ = $cgivars{$_}\n" ;
}

# Print close of HTML file
print <<EOF ;
</ul>
</body>
</html>
EOF

exit ;

#----------------- start of &getcgivars() module ----------------------

# Read all CGI vars into an associative array.
# If multiple input fields have the same name, they are concatenated
into
#   one array element and delimited with the \0 character (which fails
if
#   the input has any \0 characters, very unlikely but conceivably
possible).
# Currently only supports Content-Type of
application/x-www-form-urlencoded.
sub getcgivars {
    local($in, %in) ;
    local($name, $value) ;


    # First, read entire string of CGI vars into $in
    if ( ($ENV{'REQUEST_METHOD'} eq 'GET') ||
         ($ENV{'REQUEST_METHOD'} eq 'HEAD') ) {
        $in= $ENV{'QUERY_STRING'} ;

    } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
        if ($ENV{'CONTENT_TYPE'}=~
m#^application/x-www-form-urlencoded$#i) {
            $ENV{'CONTENT_LENGTH'}
                || &HTMLdie("No Content-Length sent with the POST
request.") ;
            read(STDIN, $in, $ENV{'CONTENT_LENGTH'}) ;

        } else {
            &HTMLdie("Unsupported Content-Type: $ENV{'CONTENT_TYPE'}") ;

        }

    } else {
        &HTMLdie("Script was called with unsupported REQUEST_METHOD.") ;

    }

    # Resolve and unencode name/value pairs into %in
    foreach (split('&', $in)) {
        s/\+/ /g ;
        ($name, $value)= split('=', $_, 2) ;
        $name=~ s/%(..)/chr(hex($1))/ge ;
        $value=~ s/%(..)/chr(hex($1))/ge ;
        $in{$name}.= "\0" if defined($in{$name}) ;  # concatenate
multiple vars
        $in{$name}.= $value ;
    }

    return %in ;

}


# Die, outputting HTML error page
# If no $title, use a default title
sub HTMLdie {
    local($msg,$title)= @_ ;
    $title || ($title= "CGI Error") ;
    print <<EOF ;
Content-type: text/html

<html>
<head>
<title>$title</title>
</head>
<body>
<h1>$title</h1>
<h3>$msg</h3>
</body>
</html>
EOF

    exit ;
}


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











--------------C9B112D35A92F0CEDA3BAEA4
Content-Type: text/x-vcard; charset=us-ascii;
 name="eric.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Eric Gessner
Content-Disposition: attachment;
 filename="eric.vcf"

begin:vcard 
n:Gessner;Eric
tel;fax:717-522-9202
tel;home:717-523-1705
tel;work:717-522-9200
x-mozilla-html:TRUE
url:http://www.egdc.net
org:EGDC.net
adr:;;P.O. Box 5;Lewisburg;PA;17837;USA
version:2.1
email;internet:eric@egdc.net
title:Web Site/Multimedia Developer
note:ICQ# - 6331962
x-mozilla-cpt:;3
fn:Eric Gessner
end:vcard

--------------C9B112D35A92F0CEDA3BAEA4--



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

Date: Mon, 23 Nov 1998 02:02:16 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: UPDATE! HELP!!!!
Message-Id: <Im362.94$wg2.221@nsw.nnrp.telstra.net>

Please read the following information on how to choose a good subject
line: http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

Also: If you post a followup to your own article, don't copy the whole
article and start a new thread. Just follow up to your original.

Since your article doesn't mention the use of a module anywhere, while
it most definitely _should_, this thread has no relevance to
clp.modules. Followups set.

In article <36586DCE.253D440D@egdc.net>,
	Eric Gessner <eric@egdc.net> writes:
> This is a multi-part message in MIME format.
> --------------C9B112D35A92F0CEDA3BAEA4

Please don't do this. usenet is a plain text medium. MIME multi-part
crap has no place here.

And since you seem to have violated almost every rule about Usenet, I
urge you to visit the group news.announce.newusers and read some of
the articles posted there.

> Also, after I get the below names into a list or an array, how do i chop
> off the "car_"?

s/^car_//;

> some of the other fields have generic names.  putting the "car_" in
> front of certain fields allows me to search for these and return them
> into a list.  that's my problem.  how do i get them into a list?

Put them in a list. I really fail to see what the problem is. Do you
mean that you want to have some magic  function that returns all the
variables that start with 'car_' in a list?

if you're using the CGI module:

	my @list = grep { /^cars_/ } $query->param;

Or something like that. If you're not using that module, I can only
advise you to start using it. Otherwise you'll find yourslef asking
these sorts of questions, and many others, regularly.

If you are allergic to good modules, here's a general recipe: Put all
of the parameter/value pairs in a hash, or even better, two arrays.
Use the grep function, as demonstrated above, to get only the ones
you're interested in.

> also, each of the above categories have a number VALUE assigned. Like,
> 
> "car_Premium Sound Pkg. I" -- 370
> "car_Premium Sound Pkg. II" -- 590
> "car_Security system upgrade" -- 200

my $sum = 0;
foreach (@list)
{
	my $val = $query->param($_};
	$sum += $val;
}

> #!/usr/bin/perl

No -w flag?
No use strict?
No use CGI?

> sub getcgivars {
>     local($in, %in) ;
>     local($name, $value) ;

Ah, you're reinventing the wheel. And probably incorrectly. Again: Use
the CGI module. If you have troubles with something as basic as this,
please use CGI.

Martien
-- 
Martien Verbruggen                  | My friend has a baby. I'm writing down
Webmaster www.tradingpost.com.au    | all the noises the baby makes so later
Commercial Dynamics Pty. Ltd.       | I can ask him what he meant - Steven
NSW, Australia                      | Wright


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4276
**************************************

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