[16471] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3883 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 2 09:10:25 2000

Date: Wed, 2 Aug 2000 06:10:17 -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: <965221816-v9-i3883@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 2 Aug 2000     Volume: 9 Number: 3883

Today's topics:
        Regexp problem <eric.selin@pp.inet.fi>
    Re: Regexp problem <elephant@squirrelgroup.com>
    Re: Regexp problem <eric.selin@pp.inet.fi>
    Re: Regexp problem <debjit@oyeindia.com>
    Re: Regexp problem (Bernard El-Hagin)
    Re: Regexp problem (Keith Calvert Ivey)
    Re: Remove a blank line <elephant@squirrelgroup.com>
    Re: Remove comments <elephant@squirrelgroup.com>
    Re: Same data accesed twice? (cleaned up code) <mikek@worldwebserver.com>
    Re: splitting on spaces (Anno Siegel)
        Upload File??? <abel@inlander.es>
    Re: Uploading files from a Win9x computer <jevon@islandtelecom.com>
        Using symbolic references to call methods decided at ru <david.t.liu@intel.com>
    Re: Variable Scope in Included Files bluearchtop@my-deja.com
    Re: Whats wrong with this???? (Keith Calvert Ivey)
    Re: WWWBoard.PL <extern.marcus.lipke@volkswagen.de>
    Re: WWWBoard.PL <martin@fez.dk>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 02 Aug 2000 10:40:57 GMT
From: "Eric Selin" <eric.selin@pp.inet.fi>
Subject: Regexp problem
Message-Id: <ZUSh5.1330$Av5.34180@news.kpnqwest.fi>

How do I delete ALL (inkl. \n) characters between words?
Example:
<!--start-->
nasflkag
adfgsdf
sdsdfggfs
sdfg
<!--end-->
Would be ereased. Of course there can be * number of lines between start and
end.

Thanks,  Eric




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

Date: Wed, 02 Aug 2000 11:03:27 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Regexp problem
Message-Id: <MPG.13f29d5c91f5aed99896a9@news>

Eric Selin writes ..
>How do I delete ALL (inkl. \n) characters between words?
>Example:
><!--start-->
>nasflkag
>adfgsdf
>sdsdfggfs
>sdfg
><!--end-->
>Would be ereased. Of course there can be * number of lines between start and
>end.

check out the range operators ('..' and '...') in perlop

  perldoc perlop

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


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

Date: Wed, 02 Aug 2000 11:27:34 GMT
From: "Eric Selin" <eric.selin@pp.inet.fi>
Subject: Re: Regexp problem
Message-Id: <GATh5.1335$Av5.34374@news.kpnqwest.fi>

I sorry to say that I don't understand much of that...
Should'nt this work: [.\n]*
Thaks,  Eric

"jason" <elephant@squirrelgroup.com> wrote in message
news:MPG.13f29d5c91f5aed99896a9@news...
> Eric Selin writes ..
> >How do I delete ALL (inkl. \n) characters between words?
> >Example:
> ><!--start-->
> >nasflkag
> >adfgsdf
> >sdsdfggfs
> >sdfg
> ><!--end-->
> >Would be ereased. Of course there can be * number of lines between start
and
> >end.
>
> check out the range operators ('..' and '...') in perlop
>
>   perldoc perlop
>
> --
>   jason -- elephant@squirrelgroup.com --




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

Date: Wed, 2 Aug 2000 17:07:11 +0530
From: "Debjit" <debjit@oyeindia.com>
Subject: Re: Regexp problem
Message-Id: <8ma5v0$oug$1@news.vsnl.net.in>

This program appears to work:
#!/usr/bin/perl -w
use strict;
open(TEXT, 'testdel.txt') or die "Cannot open text file: $!";
my $text_body;
while(<TEXT>) {
 $text_body .= $_;
}
$text_body =~s/<!--start-->.*<!--end-->//gs;
print $text_body;
--OUTPUT--
Example:

Would be ereased. Of course there can be * number of lines between start and
end.
---
--testdel.txt--
Example:
<!--start-->
nasflkag
adfgsdf
sdsdfggfs
sdfg
<!--end-->
Would be ereased. Of course there can be * number of lines between start and
end.


Eric Selin wrote in message ...
>How do I delete ALL (inkl. \n) characters between words?
>Example:
><!--start-->
>nasflkag
>adfgsdf
>sdsdfggfs
>sdfg
><!--end-->
>Would be ereased. Of course there can be * number of lines between start
and
>end.
>
>Thanks,  Eric
>
>




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

Date: Wed, 02 Aug 2000 12:12:11 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Regexp problem
Message-Id: <slrn8og3ns.61h.bernard.el-hagin@gdndev25.lido-tech>

On Wed, 02 Aug 2000 10:40:57 GMT, Eric Selin <eric.selin@pp.inet.fi> wrote:
>How do I delete ALL (inkl. \n) characters between words?
>Example:
><!--start-->
>nasflkag
>adfgsdf
>sdsdfggfs
>sdfg
><!--end-->
>Would be ereased. Of course there can be * number of lines between start and
>end.

RTFFAQ.

Bernard


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

Date: Wed, 02 Aug 2000 12:18:53 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Regexp problem
Message-Id: <399010cf.38112082@news.newsguy.com>

"Debjit" <debjit@oyeindia.com> wrote:

>my $text_body;
>while(<TEXT>) {
> $text_body .= $_;
>}

Slurp it all at once by undefining $/:

  { local $/; $text_body = <TEXT>; }

>$text_body =~s/<!--start-->.*<!--end-->//gs;

The /g isn't doing anything there, since you'll delete
everything from the first "<!--start-->" to the last
"<!--end-->".  You want nongreedy matching (.*?) -- then the /g
will have a purpose, and you won't lose chunks of your file
unexpectedly.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Wed, 02 Aug 2000 10:53:26 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Remove a blank line
Message-Id: <MPG.13f29af0f95e42639896a7@news>

Rashid Saharudin writes ..
>This is how I tried:
>
>$text="c:/scripts/text.txt";
>open TEXT, $text or die "Cannot open $text for read :$!";
>
>while (<TEXT>) {
> $text =~ s/\'.*//;
  ^^^^^...your line is NOT in the $text variable it's in $_

> next if s/\r\n//g;

this line will strip of any CRLFs (which chomp will do below on Win32) 
and jump to the next line of the file when it succeeds (almost certainly 
on every line)

>	next if /^\s*$/;
> chomp;
> print;
>}
>
>*** And this is my text file:
>
>This is my first
>
>perl script. Just
>
>testing!!! It does
>
>not work??? 'command
>
>lines using visual basic '
>
>**&& And I want it to look like this:
>
>This is my first
>perl script. Just
>testing!!! It does
>not work???
>
>&&& Also I would like when I open the text file afterwards, it looks
>exactly as above after the removal of blank lines and comments.

ok .. then you need to do a fair bit more than you're doing .. just 
follow things through logically

we want to strip out the lines with nothing on them - or only whitespace 
on them (your spec said nothing on them - but you code suggests that you 
want lines with only whitespace also stripped)

and you also want to get rid of any matching 's inclusive of included 
characters .. and those matching 's can span multiple lines

because they can span multiple lines then we will not want to do them in 
the while loop .. so first build a string of our input (stripping 
'blank' lines as we go) .. THEN do the substitution for matching 's

then write the result out to the original file


#!/usr/bin/perl -w
use strict;

my $text = 'c:/scripts/text.txt';

my $data;

open FILE, $text or die "Bad open: $!";

# obviously everything's pretty much the same up to this point
# but here we're going to build one big string so we can do the
# ' substitutions after the while loop ends
while(<FILE>)
{
  # append the line unless it's blank
  $data .= $_ unless /^\s*$/;
}

# the following substitution - while keeping with your specs - is
# potentially inadequate because if your other code ever contains a '
# then the substitution will fail
$data =~ s/'[^']*'//g;

# now we just write it out (the open will force a close)
open FILE, ">$text" or die "Bad open: $!";
print FILE $data or die "Bad print: $!";
close FILE or die "Bad close: $!";

__END__

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


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

Date: Wed, 02 Aug 2000 10:54:47 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Remove comments
Message-Id: <MPG.13f29b546f7348259896a8@news>

Rashid Saharudin writes ..
>I would like to remove comments in a asp/ VB script file like this.
>
>
>'Retrieve Country List
>
>Could anyone give me the right coding for me please.

now you're just looking for spoon feeding

  perldoc perlre

that's too simple to answer (and in fact you've stumbled over the answer 
in your previous thread on blank linkes)

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


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

Date: Wed, 02 Aug 2000 12:54:34 GMT
From: "Mike King @work" <mikek@worldwebserver.com>
Subject: Re: Same data accesed twice? (cleaned up code)
Message-Id: <39881A15.DDB4E2C1@worldwebserver.com>



Debjit wrote:
> 
> Did u try printing the sql and try it from sql prompt?

or maybe using $dbh->errstr to find out if SQL is complaining about
anything?

-Mike


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

Date: 2 Aug 2000 10:16:32 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: splitting on spaces
Message-Id: <8m8se0$i3u$1@lublin.zrz.tu-berlin.de>

Dilworth  <dilworth@megsinet.net> wrote in comp.lang.perl.misc:

> The s/ +//g should indeed be s/ +/ /g (i.e. space between the 2nd and 3rd
>"/").  Fat fingers today.  Sorry about that.  I pride myself on being
>embarassed as much and as often as possible and am glad that folks point out
>my shortcomings. :-(

[radical jeopardectomy by amputation of everything else]

Please post your replies so that they follow, not precede, what you
are replying to.

As for s/ +/ /g, there is a specialized tool that does the same thing,
only faster: tr/ //s.

Anno


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

Date: Wed, 02 Aug 2000 12:39:18 GMT
From: Abel Almazan <abel@inlander.es>
Subject: Upload File???
Message-Id: <3988166E.F5381AB2@inlander.es>

Hi,

I need to upload a file and i have a perl that do that, but...

i need to retrieve more information from the form (like description,
etc..) and i don't know how to get this info.

normallly i use CGI.pm and param('<name of the field>'), but i don't
hope this work this time.

Help, please

Reply me to my mail address too.

Thanx



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

Date: Wed, 02 Aug 2000 12:33:56 GMT
From: "Jevon MacDonald" <jevon@islandtelecom.com>
Subject: Re: Uploading files from a Win9x computer
Message-Id: <UyUh5.26$A4.8314@sapphire.mtt.net>

Use the Unix machine's filesystem (a Unix path).



"Mike Huang-R52270" <r52270@email.sps.mot.com> wrote in message
news:3980781F.DA1FE5AD@email.sps.mot.com...
> When uploading files from a Win9x computer, the file is saved with the
> full path.
>
> Ex. D:\Folder\Temp\a_file.txt
>
> I don't get this problem from a unix box. On a unix, i only get (
> a_file.txt ), not the whole path.
> I am using Perl's CGI module, and following the examples in the manpage.
>
> Anyone know how to fix this?
>




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

Date: Wed, 2 Aug 2000 02:40:16 -0700
From: "David T. Liu" <david.t.liu@intel.com>
Subject: Using symbolic references to call methods decided at run-time.
Message-Id: <8m9352$edb@news.or.intel.com>

For example:

package Class;

  sub new{ bless { }, shift;  }

sub f1{
  print "in f1\n";
}

sub f2{
  print "in f2\n";
}

package main;
main();

sub main(){
  $guy = new Class;

  my $string = "f2";

  &{$guy->{$string}};
}

How would I decide on which method of guy to call depending on the value of
$string) ?




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

Date: Wed, 02 Aug 2000 12:35:22 GMT
From: bluearchtop@my-deja.com
Subject: Re: Variable Scope in Included Files
Message-Id: <8m94ia$lim$1@nnrp1.deja.com>

In article <398786D2.82D3ECCD@jpl.nasa.gov>,
  Jonathan.L.Ericson@jpl.nasa.gov wrote:
> bluearchtop@my-deja.com wrote:
> > How can I do something like this:
> >
> > file1.pl
> > -----------
> > require 'messages.pl';
> > $var = "rainy";
> > print $e_msg;
> >
> > messages.pl
> > -------------
> > $e_msg = "Today is $var";
> >
> > perl file1.pl produced:
> > Today is
> >
> > I want it to say
> > Today is rainy.
> >
> > How would I make that work? I have to put the require statement in
the
> > begining of the file, there is no way I can get around that.
> >
> > Would I have to use a regexp on the $e_msg to look for $variables?
>
> Perhaps the printf function is what you are searching for.  Perhaps
> messages.pl should have functions instead of variables.  Perhaps you
> would get a better answer if you told us what you are really trying to
> do (i.e., I want to share my error messages across a number of
> scripts.)  (I wonder why you are required to put the require statement
> at the _top_ of the file?)

What I am doing is taking out all error messages from a script so the
language can be easily translated to other languages.  This works fine
when it is a boilerplate, static message, but when there are variables
involved, they are out of scope in the required file. I'm assuming it
is because the file is included before the variables are even set.

I know I can solve the problem by post parsing the error strings, but I
wanted to know if there was an easier way first.


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


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

Date: Wed, 02 Aug 2000 12:06:53 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Whats wrong with this????
Message-Id: <398e0e5a.37482986@news.newsguy.com>

psycho <psychoNOpsSPAM@pcpatches.com.invalid> wrote:

>im haveing a problem with this trying to print to a file, can
>anyone help?
>
>Code Below:

If you want help, describe what the problem is -- don't just
post the code and hope people will wade through it.  (Don't get
me wrong -- it's good that you posted code, but an explanation
would be good too.)

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Wed, 02 Aug 2000 13:12:19 +0200
From: DV20LIP <extern.marcus.lipke@volkswagen.de>
Subject: Re: WWWBoard.PL
Message-Id: <39880213.A18EAA6A@volkswagen.de>

> Oh boy, the shit's gonna hit the fan now. :-)
>

And, what does it mean?

Marcus




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

Date: Wed, 02 Aug 2000 14:24:45 +0200
From: Martin Mouritzen <martin@fez.dk>
Subject: Re: WWWBoard.PL
Message-Id: <pn4gosoebbk9lm9sgqahvqtdrnj0oh68jb@4ax.com>

On Wed, 02 Aug 2000 13:12:19 +0200, DV20LIP
<extern.marcus.lipke@volkswagen.de> sneezed and this is what came out:

>And, what does it mean?

Nothing but shit :-)
-- 
Martin Mouritzen
 - If you have any questions, 
   please direct them to a nearby wall.


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

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


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