[7083] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 708 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 8 11:29:16 1997

Date: Tue, 8 Jul 97 08:00:23 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 8 Jul 1997     Volume: 8 Number: 708

Today's topics:
     alternative for 'eval' <"R22601@email.sps.mot.com "@email.sps.mot.com>
     Can an array have two subscripts (i.e., @array (i,j))? <fdeng@cc.memphis.edu>
     Extracting Expressions <dan@electronet.net>
     FOR QUESTION (Fan Ng)
     Re: GC and Circular structures (Erik E. Rantapaa)
     Having trouble with the READ command <deforres@acs.ucalgary.ca>
     Re: Help with getting file contents (Tung-chiang Yang)
     Re: Help with getting file contents <rootbeer@teleport.com>
     Re: How do you do a 'cut -cx-y' with Perl? <tneohcb@pc.jaring.my>
     Re: How to call another Perl script and pass arguments (Billy Chambless)
     IF Problem <jsteven@sirris.com>
     Re: IF Problem (Michael Fuhr)
     Re: Installing libwww-perl-5.10 on perl 5.004_01 fo NT  (Jamie O'Shaughnessy)
     Looking for module that supports setsid (Jete Software Inc.)
     Memory problem with reading file (Megan Webb)
     Re: NDBM on Win32 in Perl (Parillo)
     Perl on IIS: read from STDIN (cgi-bin.pl) <rwillis@bulldog.ca>
     perl w/ mysql - insert? (Shane)
     Re: Perl: Array String cutting (Bob Wilkinson)
     Re: Perl: Array String cutting (Tad McClellan)
     Re: Perl: How to delete spaces from an value/element in (Even Holen)
     premature end of script headers pauld@pncl.co.uk
     Re: read input: getopts & argv (Nathan V. Patwardhan)
     Re: recursion (Honza Pazdziora)
     removing every other character from a string (Tim  Smith)
     Setting Perl5 and Installing CGI.pm <ohhara@sws1.postech.ac.kr>
     Re: STDIN in Win32? (Even Holen)
     Re: What does <<END do? (Rich Miller)
     Re: What does <<END do? (Matthew D. Healy)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Mon, 07 Jul 1997 12:35:39 +0900
From: Ted Braun <"R22601@email.sps.mot.com "@email.sps.mot.com>
Subject: alternative for 'eval'
Message-Id: <5ppnfg$69o$1@newsgate.sps.mot.com>

I am currently passing as arguments strings which make up part of scaler
variable names into a subroutine and based on these arguments setting
values of scalar variables.  In order to get the actual value of these
scalar variables I have used eval, but I see where using eval is not
recommended for time efficiency.  Is there a more efficient way to
evaluate the results of my concated string then eval for my example
below?

blah blah blah ... # $curp3 has been set

$set_eq('pv','cur');

sub set_eq  {
    ($val1,$val2) = @_;
    eval "\$".$val1."p3=\$".$val2."p3;";
	}

I noticed that if I specifiy only "\$".$val1."p3=\$".$val2."p3;"; that
I get what I want: $pvp3=$curp3, but that the scalar variable $pvp3 is
not set to the value in $curp3 as I want (thus my use of eval).

Any help would be appreciated as I stumble my way through learnig Perl.

Thanks,
Ted


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

Date: Sun, 06 Jul 1997 21:48:40 -0500
From: F J Deng <fdeng@cc.memphis.edu>
Subject: Can an array have two subscripts (i.e., @array (i,j))?
Message-Id: <33C05907.9D8D343@cc.memphis.edu>

Sorry for asking a question that may be too elementary.  Can an array
have two subscripts, such as @array(i,j)?  I have looked my Teach
Yourself Perl 5 in 21 days and found no answer.

Thanks for helping.

Johnny



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

Date: 7 Jul 97 21:00:16 GMT
From: "Dan Wright" <dan@electronet.net>
Subject: Extracting Expressions
Message-Id: <01bc8b1b$b42c47f0$16069ccf@uranus>


I am trying to use a global substitution on a file to reformat its contents
from plain text into HTML on the fly.

The file has lines like this:

This is Headline 1
------------------------------------

This is the text that may be several lines or even...

Another paragraph.

This is Headline 2
-------------------------

More text.

Even more text.


I want to make it look like:

<TR><TD BGCOLOR=WHITE>This is Headline 1</TD></TR>
<TR><TD>This is the text that may be several lines or even...<BR>
Another paragraph.</TD></TR>

<TR><TD BGCOLOR=WHITE>This is Headline 2</TD></TR>
<TR><TD>More text.<BR>Even more text.</TD></TR>

Currently I have:

$wholefile = s/\w+\-+/<TR><TD BGCOLOR=WHITE>$1</TD></TR>/g;

I have never used PERL to replace expressions, only exact matching. I can't
find an example of what I'm trying to do anywhere??

Your help would be appreciated.

Thank you,
Dan Wright


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

Date: Mon, 07 Jul 1997 03:15:56 GMT
From: FANNGMAIL@prodigy.net (Fan Ng)
Subject: FOR QUESTION
Message-Id: <33c15d56.18863371@news.prodigy.net>

hi there:
    Is someone know that    for ( ; <STDIN> ; )  
                                               {print;}
why stdin can't in the first or last???? and what kind the still to put in that
three EXPR in FOR.


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

Date: 7 Jul 1997 03:22:33 GMT
From: rantapaa@math.umn.edu (Erik E. Rantapaa)
Subject: Re: GC and Circular structures
Message-Id: <5ppndp$30a@epx.cis.umn.edu>

In article <hhn2o4c0lp.fsf@dres.elam.org>,
James LewisMoss  <dres@dimensional.com> wrote:
>I have come upon an instance where a circular data structure makes
>other things much easier to do.  This of course makes GC more
>difficult. :( 
[...]
>I know at what point the references have effectively dropped to
>zero (only circular ones exist) so I could do something to break the
>references if I could watch the ref count go up and down.
>
>(Please CC any replies to dres@dimensional.com.  Thank you)

Are you saying that you know when the structure isn't being used anymore?
If so all you have to do is to delete all the "back" references and Perl's
normal GC mechanism will work.

A good example of this which I ran into recently is the HTML::Parse module
(in libwww-perl at CPAN).  The sub 'parse_html' creates a structure with
circular references.  When you are done with the structure you are expected
to call $s->delete().  The 'delete' method is defined to recursively delete
all child references.  An example is:

sub delete
{
    $_[0]->delete_content;      # recurse first (depth first)
    delete $_[0]->{'_parent'};
    delete $_[0]->{'_pos'};
    $_[0] = undef;
}

In this case only '_parent' and '_pos' could contain "back" references.
Also note the difference between the 'delete' method and the delete built-in.

--
Erik Rantapaa
rantapaa@math.umn.edu
--
Erik E. Rantapaa  --  rantapaa@math.umn.edu


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

Date: Fri, 4 Jul 1997 15:33:47 -0600
From: Euan Forrester <deforres@acs.ucalgary.ca>
Subject: Having trouble with the READ command
Message-Id: <5pjq9h$iom@ds2.acs.ucalgary.ca>

I'm trying to use the read command to get a fixed length binary record
from a file. The problem, is that after I execute the command, the length
of the variable I'm storing the record into is twice the number of bytes I
specified in the read command. 

What's even wierder is that if I declare the variable with my, and give it
an initial value (say, 123) that value appears at the beginning of the
record when I try to print it to the screen (for debugging purposes).

Can anyone help me with this, or am I just doing something wrong?



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

Date: Fri, 4 Jul 1997 20:03:14 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: Help with getting file contents
Message-Id: <tcyangECt91E.MGD@netcom.com>

Nein.......  "@file_contents" bitte :)

=================================
Carsten Schabacker wrote after talking to Zeus and Hercules:

: Try this:

: open(FILE, "filename") || die("open error");
: $file_contents=<FILE>;
: close(FILE) || die("Error while reading");

--
========= Try the low-crossposting robomoderated 'alt.culture.taiwan' ===

soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
   http://www.iglou.com/tcyang/Taiwan_faq.shtml, China_faq.shtml


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

Date: Fri, 4 Jul 1997 07:04:43 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Carsten Schabacker <c.schabacker@gis.ibfs.de>
Subject: Re: Help with getting file contents
Message-Id: <Pine.GSO.3.96.970704070338.10208F-100000@kelly.teleport.com>

On 4 Jul 1997, Carsten Schabacker wrote:

> > I'd like to take a file in the same directory as my
> > script and end up with a scalar, for example $file_contents, 
> > that contains the contents of the file I want.

> open(FILE, "filename") || die("open error");
> $file_contents=<FILE>;
> close(FILE) || die("Error while reading");

You're only getting one line of the file. Thanks for trying!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 08 Jul 1997 21:13:46 +0800
From: Simon Tneoh Chee-Boon <tneohcb@pc.jaring.my>
To: Don Wallwork <wallwork@a1.flo.med.ge.com>
Subject: Re: How do you do a 'cut -cx-y' with Perl?
Message-Id: <33C23D0A.24B8@pc.jaring.my>

Don Wallwork wrote:
> while(<>) {
>   $name[$i] = cut -c0-20;       # This doesn't work.
>   $phone[$i] = cut -c21-37;
>   ...
>   $country[$i] = cut -c67-69;
>   $i++;
> }
How about regular expression?
while(<>) {
  ($name[$i], $phone[$i], ...$country[$i]) = $_ =~
/^(.{21})(.{17})...(.*)$/;
  $i++;
}
Hope this helps.

-- 
Simon Tneoh Chee-Boon
Application Developer	Hitechniaga Sdn. Bhd.
tneohcb@hitech.com.my	60-3-9660966 ext 3306
http://thccy14.oz.nthu.edu.tw:6083/simon/


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

Date: 8 Jul 1997 13:10:57 GMT
From: billy@cast.msstate.edu (Billy Chambless)
Subject: Re: How to call another Perl script and pass arguments
Message-Id: <5pte91$g34$1@NNTP.MsState.Edu>

In article <01bc8b4d$a84702e0$df2a7cc0@snore.undp.org>, "Walter Roncada" <wroncada@undp.org> writes:

|> The problem:
|>  I am trying to find a way to call a Perl script from inside a Perl script
|> and to be able to pass arguments between them. 

|> I know:
|> that I can use subroutines instead, but there will be many of them in the
|> same Perl program. Since the interpreter will parse and compile all
|> statements before running anything, it seems very inneficient to have
|> subroutines included that are only sporadically required.

Guess what?

There's More Than One Way to Do It!

Given that you have a program called "prog1", that takes two
arguments. This program can be written in Perl, C, FORTRAN, whatever.

In your main perl program, you could do

	$command = "prog1 foo bar";

then do

	system($command);

if you don't want the output, or

        $result = `$command`; # puts stdout of $command in $result

or, (if prog1 is going to have a lot of output)

	open(PROG1,"$command|") or die "can't do $command: $!\n";
	@output = (<PROG1>);
	close(PROG1);

Note that:

1) It's best to specify a full path to the program.
2) Using backticks most nearly approximates  function call/return.
3) This is just a start. Look up system() in the perlfunc manpage,
   $? and $! in the perlvar manpage, and backticks and pipes in
   (I think) the perlsyn manpage. Better yet, get "Programming Perl, 2nd
   Edition".)
-- 
*    "We all agree on the necessity of compromise.  We just can't agree on
*     when it's necessary to compromise."
*                --Larry Wall in  <1991Nov13.194420.28091@netlabs.com>



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

Date: Sun, 06 Jul 1997 15:32:25 +0000
From: "James Steven" <jsteven@sirris.com>
Subject: IF Problem
Message-Id: <5pp6qk$8rh$1@brokaw.wa.com>

What's wrong with this IF Statement? Every time it executes it runs the
first IF case, I've tried everything!

if ($subdname=="my.yagoo.com")  {
$HTML_File = "my.html";
open (HTMLOUT, "$Data_Dir\/$HTML_File");
read(HTMLOUT,$FinalHTMLOut,200000);
close (HTMLOUT);
print $FinalHTMLOut;
} elsif ( $subdname = "cool.yagoo.com" ) {
(I've left out the rest...)
I can never get this elsif statement to run even when I set subdname to
"cool.yagoo.com"

I would really aperciatle any help, this bugger has been bothering me for
days.

-James Steven


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

Date: 6 Jul 1997 22:50:32 -0600
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: IF Problem
Message-Id: <5ppsio$gd3@flatland.dimensional.com>

"James Steven" <jsteven@sirris.com> writes:

> What's wrong with this IF Statement? Every time it executes it runs the
> first IF case, I've tried everything!
>
> if ($subdname=="my.yagoo.com")  {

-snip-

> } elsif ( $subdname = "cool.yagoo.com" ) {

Check out the perlop manual page and read about the various types of
comparison operators.  Hope this helps.

-- 
Michael Fuhr
http://www.dimensional.com/~mfuhr/


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

Date: Tue, 08 Jul 1997 09:38:43 GMT
From: joshaugh@uk.oracle.com (Jamie O'Shaughnessy)
Subject: Re: Installing libwww-perl-5.10 on perl 5.004_01 fo NT - problems
Message-Id: <33c30a19.1097715703@newshost.us.oracle.com>

On 07 Jul 1997 19:48:00 +0200, Gisle Aas <aas@bergen.sn.no> wrote:

>Patches that make the LWP test suite work on Win32 will be accepted.
>
>-- 
>Gisle Aas <aas@sn.no>

The following will run the libwww-perl-5.10 tests on Win32 but I haven't got
the facilities to test it on other platforms. Just replace
libwww-perl-5.10\t\TEST with the following script. I get a 91.98% success rate
for the tests on Win32. I'll try to sort out any of the problems if I've got
time.

use Test::Harness qw(&runtests $verbose); 

unshift(@INC, "blib/lib", "blib/arch");

$verbose = shift
  if $ARGV[0] =~ /^\d+$/ || $ARGV[0] eq "-v";

if(@ARGV) {
   for(@ARGV) {
      if(-d $_) {
         push(@tests, glob("t/$_/*.t"));
      } else {
         $_ .= ".t" unless /\.t$/;
         push(@tests, $_);
      }
   }
} else {
   @tests = (glob("t/base/*.t"), 
             glob("t/html/*.t"), 
             glob("t/robot/*.t"),
             glob("t/local/*.t"),
            );
   push(@tests, glob("t/net/*.t")) if -f "t/net/config.pl";
}

runtests @tests;

___________________________________________________________________________ 
Jamie O'Shaughnessy                        Work: joshaugh@uk.oracle.com 
Oracle Designer/2000 Forms Generator Team  Home: jamie@thanatar.demon.co.uk 
______________________________________________________  __  __ _  __ .   __ 
Opinions expressed here are my own and not those of... (__)|-</-\(__ |__ -_ 


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

Date: 6 Jul 1997 22:26:16 -0400
From: jete@dgs.dgsys.com (Jete Software Inc.)
Subject: Looking for module that supports setsid
Message-Id: <5ppk48$5r1@dgs.dgsys.com>

Most System V Unixes contain a setsid() and getsid() system call. Is
there a module that supports these calls??

-- Norman


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

Date: 7 Jul 1997 00:42:24 GMT
From: mwebb@mail.usyd.edu.au (Megan Webb)
Subject: Memory problem with reading file
Message-Id: <5ppe1g$bd7@metro.usyd.edu.au>
Keywords: memory file

 
 Hi,
 
 Maybe I am doing this completely wrong, but...
 I have a data file that is 27.5 Meg of ascii data,
 made up of 1,286,800 records. The records are in the format of
 
 <int>,<char>,< up to 6 char>,<int>,<int>
 11112345,T,ASDASD,366,456
 
 Yet when I use the code below the memory useage peaks at 237 Meg!
 
 use strict;
 {
 
         my $task = "data+file" ;
         my @row;
         open(TASK, $task ) or die "cannot open $task";
 
         my %rec;
         my %list;
         my $count=0;
         my $last = "--";
 
         while(<TASK>)
         {
                 chomp;
                 @row = split /,/ ;
                 if ($last ne $row[2])
                 {
                         $last = $row[2];
                         $count=0;
                 }
                 else
                 {
                         $count++;
                 }
 
                 $rec{$row[2].",". $count} = $_;
                 $list{$row[2]}=".";
         }
         close TASK;
 }
 
 Even this peaks at 200 Meg
 
 {
         my $task = "data_file";
         my @row;
         open(TASK, $task ) or die "cannot open $task";
         @row=<TASK>;
         close TASK;
 }
 
 What is happening?
 
 Megan
 mwebb@extro.ucc.su.oz.au


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

Date: 8 Jul 1997 13:46:52 GMT
From: lparillo@newshost.li.net (Parillo)
Subject: Re: NDBM on Win32 in Perl
Message-Id: <5ptgcc$7c7@linet06.li.net>

And so I did.
And it worked.
Is the warning message (copied into the comments) important?
I would hate to have to turn off strict or the -w

#!c:\perl\bin\perl -w

# This is the error message I get....
# C:\Perl\bin>perl -w \temp\tietest.pl2
# Can't locate package AutoLoader for @DynaLoader::ISA at 
# \temp\tietest.pl2 line 5.
#
# But the output comes out fine
# (key is from previous run, key1 and key2 are from this run)
# key: value
# key1: value1
# key2: value2
#

require 5.001;
use strict;
use SDBM_File;

MAIN:

{

  my %db_write;
  my %db_read;

  sub O_CREAT  { 0x0100 }
  sub O_BINARY { 0x8000 }
  sub O_RDWR   { 0x0002 }

  tie (%db_write, 'SDBM_File', 'c:/temp/my_db', O_RDWR | O_CREAT | 
O_BINARY, 0666)
     or die "write tie died;-)";
  $db_write{"key1"} = "value1";
  $db_write{"key2"} = "value2";
  untie %db_write;

  tie (%db_read, 'SDBM_File', 'c:/temp/my_db', O_RDWR | O_CREAT | 
O_BINARY, 0666)
     or die "read tie died;-)";
  foreach (keys %db_read) {print "$_: $db_read{$_}\n"}
  untie %db_read;

}

Neil Kohl (neilkohl@netaxs.com) wrote:

: Nope. SDBM_File is supported.

: Try something like:

: use SDBM_File;

: #flags for SDBM
: sub O_CREAT { 0x0100 }
: sub O_BINARY { 0x8000 }
: sub O_RDWR { 0x0002 }
:  
: my %db;
: tie (%db, "SDBM_File", "$dbm_file_name", O_RDWR | O_CREAT | O_BINARY,
: 0666) or die "tie die!";
: # fiddle with data here...
: untie %db;

: SDBM files aren't as compact as other formats, but they work...
: -- 
: neil kohl
: =====================================================================
: neilkohl@netaxs.com |             "A long quiet like a purge and then
: philadelphia, pa    |    a contemplation and decision of future roads,
: usa                 |                 that is what to look forward to." 
:                     |                       - T.E. Lawrence, 15.vi.18
: =====================================================================


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

Date: Fri, 04 Jul 1997 21:30:13 -0400
From: Richard Willis <rwillis@bulldog.ca>
Subject: Perl on IIS: read from STDIN (cgi-bin.pl)
Message-Id: <33BDA3A5.5172@bulldog.ca>

I have a Web application running on Unix and NT (Netscape server) that I
am trying to get working on NT using an IIS Web server. Part of my
application is written in Perl. Everything works except for one script
(it's actually a fairly standard one, cgi-bin.pl, which reads in GET or
POST data, converts it to unescaped text, and puts key/varlue pairs in
%in). 

When the request method is POST, and the Perl script tries to read from
STDIN, the script hangs. I have tried with several different versions of
NT Perl interpreters, as well as mucking about in the bowels of the Type
Registry, as IIS documentation suggests. I got a response from the
people who wrote cgi-bin.pl in the first place, but they could only say
they believed it would work with the right IIS configuration.

Any ideas out there?


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

Date: Tue, 08 Jul 1997 14:56:33 GMT
From: zatezalo.2@osu.edu (Shane)
Subject: perl w/ mysql - insert?
Message-Id: <33c252b8.96278042@achilles.medctr.ohio-state.edu>

I've been using Perl5 w/ mySql - I've read through the FAQ, etc, and
can't figure this out.

I can connect to a database, I can query it, but how in the world do I
insert data into it using perl?

It'd go something like this (arbitrary sql database w/ employee info
(name, ph#, etc) in it):


use Mysql;
$dbh = Mysql->Connect($host,$database,$password,$user); 
$dbh->SelectDB($database);

# run a simple query
$sth = $dbh->Query("SELECT name,number FROM phones_table") or die
$Mysql::db_errstr; 

while(@record = $sth->FetchRow) { 
   $name   = $record[0];
   $number = $record[1];
   if ($name eq "shane") {
	$sth=$dbh->Query("Insert into phones_table (name, number)
values (\"Shane2\",\"614-xxx-xxxx\"") or die $mysql::db_errstr;
   }
   else {
        print "name=$name number=$number\n";
   }
}
exit;





--
zatezalo.2@osu.edu
http://www.ecaetc.ohio-state.edu/shane


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

Date: Fri, 04 Jul 1997 15:29:37 +0100
From: b.wilkinson@pindar.co.uk (Bob Wilkinson)
Subject: Re: Perl: Array String cutting
Message-Id: <b.wilkinson-0407971529370001@ip57-york.pindar.co.uk>

In article <33BCDD53.6560@eei.ericsson.se>, Shaun O'Shea
<lmisosa@eei.ericsson.se> wrote:

> Hi,
>         I'm an electronic Eng student engaged in summer work. I was told to
> learn Perl & CGI & UNIX( Yes I know, imagine not being taught unix in
> college!) to do the task assigned to me so bear with me cos I've only
> been doin Perl for the last month.
> 
> Anyway le problem:
> 
>         I have an array called @type whose elements are of the form:
> 155 04-
> 143 12-
> 3/155 04-
> 206 34-
> 13/143 12-
> etc
> 
> i.e some of the elements have a number followed by a "/" at the
> beginning. I want to remove the the  "number/" bit from the elements
> which have them.
> 
> Thanking you in advance,
> -- 
> ***********************************************************************
>                            Shaun
O'Shea                                                
lmisosa@eei.ericsson.se   OR   
> shaunos@orca.ucd.ie
> 
> ***********************************************************************

Hello,

      This code should illustrate what you'd need to do.

#!/usr/local/bin/perl -w
use strict;
use diagnostics;
my @type=("155 04-","143 12-","3/155 04-","206 34-","13/143 12-");
foreach (@type) {
        print "OLD : $_\n";
}
foreach (@type) {
        s|^\d+/||; # this removes the unwanted characters
}
foreach (@type) {
        print "NEW : $_\n";
}

Output is :

OLD : 155 04-
OLD : 143 12-
OLD : 3/155 04-
OLD : 206 34-
OLD : 13/143 12-
NEW : 155 04-
NEW : 143 12-
NEW : 155 04-
NEW : 206 34-
NEW : 143 12-

Bob

-- 
Do what thou wilt shall be the whole of the law.


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

Date: Fri, 4 Jul 1997 13:29:26 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Perl: Array String cutting
Message-Id: <6efjp5.nv9.ln@localhost>

Shaun O'Shea (lmisosa@eei.ericsson.se) wrote:

: 	I'm an electronic Eng student engaged in summer work. I was told to
: learn Perl & CGI & UNIX( Yes I know, imagine not being taught unix in
: college!) to do the task assigned to me so bear with me cos I've only
: been doin Perl for the last month.

: i.e some of the elements have a number followed by a "/" at the
: beginning. I want to remove the the  "number/" bit from the elements
: which have them.


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

while (<DATA>) {
   chomp;
   push(@type, $_);
}

foreach (@type) {
   print "BEFORE: $_\n";
   s!^                 # match beginning of line
     \d+               # match one or more digits
     /                 # match a literal slash character
    !!x;               # replace them with nothing (delete 'em)
   print "AFTER : $_\n\n";
}


__DATA__
155 04-
143 12-
3/155 04-
206 34-
13/143 12-
------------------------


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 5 Jul 1997 16:35:37 GMT
From: evenh@ra.pvv.ntnu.no (Even Holen)
Subject: Re: Perl: How to delete spaces from an value/element in an assoc array
Message-Id: <slrn5rstuh.tl.evenh@ra.pvv.ntnu.no>

In article <33B8C5D0.3A1D@eei.ericsson.se>, Shaun O'Shea wrote:
>I want to remove the spaces from something similar to the following:
>
>		152 41-cax 102 577
>
>Someone else suggested: 
>			 $string= s/\s//g;

A minor typo... This should be:
   $string =~ s/\s//g;

Not the tilde (~) character after the equal sign...

>But this seemed to remove all characters!

It's due to the lack of the tilde character.

Regards,
Even Holen
-- 
<><   Even Holen, evenh@pvv.ntnu.no, http://www.pvv.ntnu.no/~evenh/   :-)


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

Date: Tue, 08 Jul 1997 06:11:23 -0600
From: pauld@pncl.co.uk
Subject: premature end of script headers
Message-Id: <868360164.26467@dejanews.com>

Hello,
	While installing some scripts on my server (solaris 2.4, perl 5.001, I
get an error in the error_log which basically

says script failed,
"reason: Premature end of script headers".
I really don't know why this is happening as these work fine on the dev
machine. Any clues ??

Thanks

Paul
pauld@pncl.co.uk

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 7 Jul 1997 15:59:46 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: read input: getopts & argv
Message-Id: <5pr3pi$aic@fridge-nf0.shore.net>

Raju Gadiraju (rajug@bnr.ca) wrote:
: dear perl guru,

I'm not a guru, but I'll see what I can do for you.

: I'm trying to read some info. from command line in
: the foll. format:

: 	scriptabc <parameter 'X' mandatory> -p salad -q atchoo

: The parameter 'X' is mandatory where as there may be other options.

Here's a version using Getopt::Long (untested):

#!/usr/local/bin/perl -w

use Getopt::Long;
use strict;
# I think this will work if I understood your question correctly

my($X_val, $pval, $qval);
GetOptions('X', \$X_val, 'p:s', \$pval, 'q:s', \$qval);

if($X_val) {
    print $pval,"\n",$qval,"\n";
} else { 
    &usage; 
}

sub usage {
    print("Usage: $0 -X -p <this> -q <that>\n");
    exit(0);
}

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: Tue, 8 Jul 1997 08:16:17 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: recursion
Message-Id: <adelton.868349777@aisa.fi.muni.cz>

adelton@fi.muni.cz (Honza Pazdziora) writes:

> > 2)The current setup requires you to type "http://www.xxx.xxx.xxx" instead of just "www.xxx.xxx.xxx"

> > $html = get $ARGV[0];
> 
> $html = 'http:// . $html unless $html =~ m!^http://!;

I was advised that I've missed an apostrophe:

$html = 'http://' . $html unless $html =~ m!^http://!;

Sorry about that.

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: 6 Jul 1997 19:24:24 -0700
From: trs@azstarnet.com (Tim  Smith)
Subject: removing every other character from a string
Message-Id: <5ppk0o$mrd@web.azstarnet.com>

Hello, all.
I'm read'ing from a binary file where every other character describes
the color of the previous (ASCII) character.  I don't care about the
color, I just want the ASCII text.  Is there a better way than just
using s/(.)./$1/gs to strip out every other character?  It seems that
unpack() might work, but I can't figure out how to do it.

Thanks,

Tim

#!/usr/bin/perl

read DATA, $_, 8;
s/(.)./$1/gs;		# can I do better than this?
print $_, "\n";		# should print "abcd"

exit 0;

__DATA__
aXbXcXdX


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

Date: 8 Jul 1997 13:13:52 GMT
From: Taeho Oh <ohhara@sws1.postech.ac.kr>
Subject: Setting Perl5 and Installing CGI.pm
Message-Id: <5pteeg$2o4@news.postech.ac.kr>

Sorry~~
I solve this problem.

I downloaded zip file.
I should have downloaded tar.gz file.

Thank you


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

Date: 5 Jul 1997 14:09:32 GMT
From: evenh@ra.pvv.ntnu.no (Even Holen)
Subject: Re: STDIN in Win32?
Message-Id: <slrn5rslcl.s57.evenh@ra.pvv.ntnu.no>

In article <33bd5401.131698@news.cei.net>, Barbara Pfieffer wrote:
>When I run this small script, it works:
>
>print "Hello, world\n";
>print "City name? \n";
>print "\n";
>#$city = <STDIN>;
>#chomp($city);
>$city= "New York";
>if ($city eq "New York"){
>	print "New York Sucks!\n";
>}
>
>If I uncomment the $city = <STDIN>; line, and the following line,  the
>"hello world" and City name?" never come up, the cursor just blinks at
>me.  If I hit enter, it exits and prints the above.

Have you tried to enter a text like "New York" to see whether the script
actually works and does do the input?

>I'm running Win 95.  Is there something I need to do to define STDIN?
>I looked through the docs and couldn't find anything and nothing in
>the Activeware archives that was helpful.

My long shot on this one is that you've got a problem with flushing of
stdout, and not a problem with stdin. Try adding
 $| = 1;   # This line says always flush stdout!

at the top of your script, or search the documentation on how to flush
stdout.

If this is your problem then your problem can be restated to that your
script saves up several lines of output before it actually writes it to
your screen.

Try it and see whether it works with the line given! 

Regards,
Even Holen
-- 
<><   Even Holen, evenh@pvv.ntnu.no, http://www.pvv.ntnu.no/~evenh/   :-)


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

Date: 7 Jul 1997 03:18:54 GMT
From: rchmllr@netins.net (Rich Miller)
Subject: Re: What does <<END do?
Message-Id: <5ppn6u$eta$1@insosf1.netins.net>

In article <33BB9C79.41C6@fccc.edu>, Ying Hu <Y_Hu@fccc.edu> says:
>
>Wade Williams wrote:
>>           print <<END;
>        ...
>>         END
>> Can't find string terminator "END" anywhere before EOF at ./test.cgi line 77.
>
>The END should be the beginning of line, there is non space before END
>in the line.
>
>Ying


This "no space" rule can also be circumvented by placing double quotes
around the first END and prepending whatever whitespace character(s)
precede the terminator to the first END, inside the quotes:

print <<"        END";
   ...
        END

Just make sure you use precisely the same whitespace character(s) in
both places (don't use spaces in one place and a tab in the other).


Rich M.


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

Date: Mon, 07 Jul 1997 11:35:30 -0500
From: Matthew.Healy@yale.edu (Matthew D. Healy)
Subject: Re: What does <<END do?
Message-Id: <Matthew.Healy-0707971135300001@pudding.med.yale.edu>

In article <tcyangECt91H.MH0@netcom.com>, tcyang@netcom.com (Tung-chiang
Yang) wrote:

> Also no spaces after END.  Sometimes I wonder why Perl has such a rule
> since many people make this mistake, and if Perl can accept this label
> with leading and lagging spaces, it does not seem to create ambiguity.

Because if you allow too much flexibility for the ending tag, then
you increase the risk of ending when you really don't want to!  Requiring
it to be the ONLY thing on the line means you can safely put absolutely
anything else, even strings containing the here-doc terminator, within
the here-doc contents.  IMHO, the subtle bugs that could be created
by allowing heredoc terminators within longer lines would be far
worse than the way it is now.

Besides, if this month Perl is "fixed" to allow leading and trailing
spaces AND NOTHING ELSE before and after the heredoc terminator, then
probably next month somebody will demand allowing quotes around the
here-doc terminator, or a backslash in front of it, or something.

Look at the headaches caused by differences in how bourne and C shells
handle here-doc terminators!  Do we really want Perl to go down this
road?

As I see it, ambiguity is the inherent problem with virtually all
attempts to "fix" a common user error by redefining the language.  For
example, many versions of Netscape try to fix some common HTML mistakes.
As a result:

   1. I see lots of "works with Netscape, not with other browsers"
      questions on web-related newsgroups.

   2. I've also seen "works with version such-and-such" questions
      because different versions of Netscape handle these cases
      differently -- and the differences are not well documented!

   3. There are examples of _CORRECT_ HTML that cannot be handled
      properly by Netscape because the ambiguities introduced into
      the parser to "fix" common coding errors introduce bugs.

PS: I am not talking about things like NETSCAPE-specific tags here;
that's a different kind of stupidity.  I am talking about things like
the versions of Netscape that attempt to fix URLs with a missing close
quote or somesuch.

Let's not make Perl commit similar errors!
--------
Matthew.Healy@yale.edu           http://ycmi.med.yale.edu/~healy/
As of 26 Jun 1997, only 918 days until Y2K....
Any person with a phone line can become a town crier with a voice
that resonates farther than it could from any soapbox.
--The US Supreme Court, overturning the Communications Decency Act


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 708
*************************************

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