[16451] in Perl-Users-Digest
Perl-Users Digest, Issue: 3863 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 31 18:20:49 2000
Date: Mon, 31 Jul 2000 15:20:36 -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: <965082035-v9-i3863@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 31 Jul 2000 Volume: 9 Number: 3863
Today's topics:
Syntax Question bardicstorm@my-deja.com
Re: Syntax Question <tina@streetmail.com>
Re: Syntax Question (Colin Keith)
Re: Syntax Question (Greg Bacon)
Re: Syntax Question (Greg Bacon)
Re: Syntax Question <mjcarman@home.com>
Re: Syntax Question bardicstorm@my-deja.com
Re: Syntax Question bardicstorm@my-deja.com
system or backticks mchampneys@my-deja.com
Re: system or backticks <tina@streetmail.com>
Re: system or backticks <lauren_smith13@hotmail.com>
Re: text file to HTML page <todd@mrnoitall.com>
Re: text file to HTML page <bart.lateur@skynet.be>
Re: text file to HTML page <flavell@mail.cern.ch>
Re: text file to html (Colin Keith)
Re: text file to html <flavell@mail.cern.ch>
Re: text file to html (Colin Keith)
Re: tricky regexp <tim@ipac.caltech.edu>
Re: tricky regexp <tina@streetmail.com>
Re: ttt <Luc-Etienne.Brachotte@wanadoo.fr>
Uploading images via Perl script oliver.arend@gmx.de
Re: Uploading images via Perl script (Logan Shaw)
Re: Use MIME *and* specify the mail server (Colin Keith)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 31 Jul 2000 19:43:31 GMT
From: bardicstorm@my-deja.com
Subject: Syntax Question
Message-Id: <8m4kt3$cnf$1@nnrp1.deja.com>
Hey there...
I was just wondering if anyone could help me with the syntax for
reading an entire file into a string variable instead of reading in one
line at a time and looping through.
Thanks in advance...
BardicStorm...
P.S. - I'm new to PERL and this newsgroup so I'd like to give you all a
hearty hey and happy coding :)
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 31 Jul 2000 20:41:03 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Syntax Question
Message-Id: <8m4o8v$5mcr3$2@ID-24002.news.cis.dfn.de>
hi,
bardicstorm@my-deja.com wrote:
> I was just wondering if anyone could help me with the syntax for
> reading an entire file into a string variable instead of reading in one
> line at a time and looping through.
look at
perldoc perlvar
and search for the variable $/
you have to set it to undef and then do
$file = <FILEHANDLE>;
(but be sure to do this locally so that the $/ remains
untouched in the main program.)
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please no answers via email unless followup is set to poster.
------------------------------
Date: Mon, 31 Jul 2000 20:57:02 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: Syntax Question
Message-Id: <yKlh5.62$DT4.2130873@nnrp2.clara.net>
In article <8m4kt3$cnf$1@nnrp1.deja.com>, bardicstorm@my-deja.com wrote:
>Hey there...
> I was just wondering if anyone could help me with the syntax for
>reading an entire file into a string variable instead of reading in one
>line at a time and looping through.
You know, sometimes I just can't think of the simple things. And I'm sure
this is over complicated, but if you set the record separator $/ to a value
it can't be then it'll never match till the end of file and your 'line'
contains the entirity of the file. I.e.
maia% perl -w -Mstrict
$/ = \0; # assumes you don't have any NULLs in there
open(X, "<LC_TIME") || die "ick - $!";
$_ = <X>;
(Ignore the file, I was looking at LC_TIME after the exponent Q earlier)
So... someone want to tell us both the easy way to do this?
(I'm sure there is one:)
>P.S. - I'm new to PERL and this newsgroup so I'd like to give you all a
>hearty hey and happy coding :)
Yay, another one sees the shining light of goodness:)
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Mon, 31 Jul 2000 21:10:50 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Syntax Question
Message-Id: <sobqqqs155120@corp.supernews.com>
In article <8m4kt3$cnf$1@nnrp1.deja.com>,
<bardicstorm@my-deja.com> wrote:
: I was just wondering if anyone could help me with the syntax for
: reading an entire file into a string variable instead of reading in one
: line at a time and looping through.
open FILE, $file or die "$0: open $file: $!";
my $contents = do { local $/; <FILE> };
close FILE;
Greg
--
Got Mole problems?
Call Avogadro: 6.02 x 10^23
------------------------------
Date: Mon, 31 Jul 2000 21:15:15 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Syntax Question
Message-Id: <sobr33jt55142@corp.supernews.com>
In article <8m4kt3$cnf$1@nnrp1.deja.com>,
<bardicstorm@my-deja.com> wrote:
: I was just wondering if anyone could help me with the syntax for
: reading an entire file into a string variable instead of reading in one
: line at a time and looping through.
open FILE, $file or die "$0: open $file: $!";
my $contents = do { local $/; <FILE> };
close FILE;
Greg
--
The circle algorithm was invented by mistake when I tried to save one
register in a display hack!
-- Minsky
------------------------------
Date: Mon, 31 Jul 2000 15:54:07 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Syntax Question
Message-Id: <3985E76F.9EE93860@home.com>
bardicstorm@my-deja.com wrote:
>
> I was just wondering if anyone could help me with the syntax for
> reading an entire file into a string variable instead of reading in one
> line at a time and looping through.
Line-by-line processing is generally preferred, as it conserves memory.
But if you insist:
#!/usr/local/bin/perl -w
use strict;
my $file = 'somefile.txt';
my $file_contents;
{
local $/ = undef; # Turn on slurp mode
open FH, $file or die "Could not open $file: $!\n";
$file_contents = <FH>;
}
The enclosing block is just to limit the change to $/ (the
INPUT_RECORD_SEPERATOR) to the one file read and to not make it global
to the entire program.
> P.S. - I'm new to PERL and this newsgroup so I'd like to give you all a
> hearty hey and happy coding :)
Then please do yourself (and all of us) a favor by familiarizing
yourself with the resources available to you. The first is a utility
called 'perldoc' that came as part of your Perl distribution. Go to a
command line and type the following:
perldoc perldoc
perldoc perl
perldoc perltoc
Those should get you started. Perldoc contains all the standard
documentation, FAQs, and even a couple tutorials. It should be the first
place you turn with questions. Why? Because most of the questions you
(as a newbie) are likely to come up with have been asked and answered a
thousand times. The docs contain quick, handy, and *correct* answers.
Posts to Usenet are slower and more error-prone.
Next, if you've RTFM (Read The F*ing Manual) and checked the FAQ, and
you still can't find an answer, post here. There are some general
conventions on posting. Following them will improve your results and
save you the cost of asbestos pants:
* Have a meaningful subject. Things like "Help!" and "Perl question"
are not meaningful and will largely be ignored.
* If possible, include a short snippet of code which exhibits the
problem you're having.
* When responding to a post, place your comments *after* quoted text,
and quote only the things you're responding to.
In your case "Sytax Question" is a little vague. "How do I slurp a
file?" would be clearest to the locals here, but if you're not familiar
with that lingo, something like "How do I read an entire file into a
string?" would work just fine.
Enjoy...
-mjc
------------------------------
Date: Mon, 31 Jul 2000 21:23:17 GMT
From: bardicstorm@my-deja.com
Subject: Re: Syntax Question
Message-Id: <8m4qnv$hg0$1@nnrp1.deja.com>
Ahh... My thanks... had I known that was there I'd not have asked..
:)
- BardicStorm -
> look at
> perldoc perlvar
> and search for the variable $/
> you have to set it to undef and then do
> $file = <FILEHANDLE>;
>
> (but be sure to do this locally so that the $/ remains
> untouched in the main program.)
>
> tina
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 31 Jul 2000 21:44:28 GMT
From: bardicstorm@my-deja.com
Subject: Re: Syntax Question
Message-Id: <8m4rvr$id6$1@nnrp1.deja.com>
I have to admit I don't quite understand this solution.. what does the
### my $contents = do { local $/; <FILE> }; ###
line do?
> open FILE, $file or die "$0: open $file: $!";
> my $contents = do { local $/; <FILE> };
> close FILE;
>
> Greg
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 31 Jul 2000 21:04:35 GMT
From: mchampneys@my-deja.com
Subject: system or backticks
Message-Id: <8m4pl0$ght$1@nnrp1.deja.com>
I am seriously befuddled...
I am trying to execute a command line DOS program from a Perl script.
(obviously, this is on a Windows machine) The DOS program executes fine
from the command line and also from a batch file, but I can't seem get
the Perl script to execute it.
The DOS program has two arguments that need to passed to it.
I have tried the following code:
@args=("jpegsize.exe", "test.jpg", "$testt.jpg");
$test=system "@args";
I have also tried this:
$test=`jpegsize.exe test.jpg testt.jpg`;
Anybody have any ideas?
Thanks!
Matt
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 31 Jul 2000 21:27:30 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: system or backticks
Message-Id: <8m4r01$5mcr3$6@ID-24002.news.cis.dfn.de>
hi,
mchampneys@my-deja.com wrote:
> I am trying to execute a command line DOS program from a Perl script.
> (obviously, this is on a Windows machine) The DOS program executes fine
> from the command line and also from a batch file, but I can't seem get
> the Perl script to execute it.
> The DOS program has two arguments that need to passed to it.
> I have tried the following code:
> @args=("jpegsize.exe", "test.jpg", "$testt.jpg");
> $test=system "@args";
> I have also tried this:
> $test=`jpegsize.exe test.jpg testt.jpg`;
any more information about what goes wrong?
any error message?
$test = system("@args") or die $!;
btw, is this line correct?
> @args=("jpegsize.exe", "test.jpg", "$testt.jpg");
or did you want to write
@args=("jpegsize.exe", "test.jpg", "testt.jpg");
maybe you want to use the qw operator, too.
but that shouldn't solve your problem.
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please no answers via email unless followup is set to poster.
------------------------------
Date: Mon, 31 Jul 2000 14:31:28 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: system or backticks
Message-Id: <8m4r60$1dq$1@brokaw.wa.com>
<mchampneys@my-deja.com> wrote in message
news:8m4pl0$ght$1@nnrp1.deja.com...
> I am seriously befuddled...
>
> I am trying to execute a command line DOS program from a Perl script.
> (obviously, this is on a Windows machine) The DOS program executes fine
> from the command line and also from a batch file, but I can't seem get
> the Perl script to execute it.
>
> The DOS program has two arguments that need to passed to it.
>
> I have tried the following code:
>
> @args=("jpegsize.exe", "test.jpg", "$testt.jpg");
> $test=system "@args";
>
> I have also tried this:
>
> $test=`jpegsize.exe test.jpg testt.jpg`;
>
> Anybody have any ideas?
Are you in the right directory to execute jpegsize.exe?
What are you trying to capture in $test?
Have you read the documentation for system() (which also describes the
backticks, and their respective differences)?
perldoc -f system
Lauren
------------------------------
Date: Mon, 31 Jul 2000 12:20:36 -0600
From: Todd Anderson <todd@mrnoitall.com>
Subject: Re: text file to HTML page
Message-Id: <3985C36E.48E7CCE7@mrnoitall.com>
Dr M Hughes wrote:
> Please could someone tell me how to convert the results of a program
> that are in the way of a text file (.txt as i'm on windows) into an HTML file
> that I can return to the browser in my CGI script?
>
> Thanks
> Rich
>
> please reply to r.dobson@microscience.com
You don't need to convert it to html. Your browser will open a txt file as is.
Some people set thier preferences to open txt files in another application so
you could change the suffix to html causing only a browser to display the txt.
------------------------------
Date: Mon, 31 Jul 2000 19:55:41 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: text file to HTML page
Message-Id: <mblbosg082ng1jf0ifksc48nb9t32m6u90@4ax.com>
Dr M Hughes wrote:
>Please could someone tell me how to convert the results of a program
>that are in the way of a text file (.txt as i'm on windows) into an HTML file
>that I can return to the browser in my CGI script?
print "<pre>\n";
print <FILE>;
print "</pre>";
:-)
But anyway, what you probably want, is a template mechanism. That is a
mechanism to insert plain text (could well be HTML-ified) into a HTML
template.
There are several modules that can do that, search CPAN
(<http://search.cpan.org/>) to find them.
<http://search.cpan.org/search?mode=module&query=template>.
You may not even need a template mechanism: if your script needs to
produce just one type of HTML file, you can embed the template file into
your script using the here-doc syntax:
print <<"#EOT#";
... html file, or part of it, follows here
... in which variables, or hash elements, may be embedded
which will be interpolated.
#EOT#
Note that the end string, here "#EOT#", must be on it's own line with
nothing before (no extra spaces!) or after it.
You'll need a HTML-escaping function. I like to use MJD's
"Interpolation" module to embed it:
use CGI; sub HTMLescape { CGI->escapeHTML(@_); } # for example
use Interpolation HTML => \&HTMLescape;
$test = '<&foo>';
print "This is $HTML{$test}.\n";
--
Bart.
------------------------------
Date: Mon, 31 Jul 2000 22:16:04 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: text file to HTML page
Message-Id: <Pine.GHP.4.21.0007312206110.22351-100000@hpplus03.cern.ch>
On Mon, 31 Jul 2000, Bart Lateur wrote:
> print "<pre>\n";
> print <FILE>;
> print "</pre>";
Bzzt, I'm afraid you also win the CERT lead medal, for passing on
potentially malicious content unchecked. See CA-2000-02 for the
potential penalties :-}
The <pre> tag does _not_ override HTML's special treatment of '&'
and '<' characters.
[..]
> You'll need a HTML-escaping function.
Indeed you do. Even inside <pre>
all the best
------------------------------
Date: Mon, 31 Jul 2000 19:59:09 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: text file to html
Message-Id: <hUkh5.58$DT4.2123192@nnrp2.clara.net>
In article <Pine.GHP.4.21.0007311543570.9724-100000@hpplus03.cern.ch>, "Alan J. Flavell" <flavell@mail.cern.ch> wrote:
>On Mon, 31 Jul 2000, Colin Keith wrote:
>
>> print "<HTML><HEAD><TITLE>readme.txt</TITLE></HEAD><BODY>\n";
>> while(defined($_ = <TXT>)){
>> print;
>> }
>
>[..]
>
>Bzzt, thanks for playing. Please pick up a copy of security alert
>CA-2000-02 on your way out of the studio.
Uh huh okay, and I missed the security threat of reading from a file that I
created and placed on the disk from my CGI script to my user's connection.
>CA-2000-02
| Systems Affected
| + Web browsers
| + Web servers that dynamically generate pages based on unvalidated input
Well it isn't the second and the first is.. broad.
| Overview
| A web site may inadvertently include malicious HTML tags or script in
| a dynamically generated page based on unvalidated input from
| untrustworthy sources. This can be a problem when a web server does not
| adequately ensure that generated pages are properly encoded to prevent
| unintended execution of scripts, and when input is not validated to
| prevent malicious HTML from being presented to the user.
Nope, entirely correct. I wrote the text file so I can put what I want in
it. I leave it up to the OS to stop malicious users from changing the
contents of my file. I didn't take any input from anywhere else, so the
problem lies where ... ?
| Malicious code provided by one client for another client
Nope, nothing is read from anywhere but the file on disk.
| Malicious code sent inadvertently by a client for itself
ditto
| Abuse of other tags
Yeah, I could start really rocking the boat and let that text file of *mine*
written by *me* use <SCRIPT> tags. (or Worse <APPLET> :*)
| Users may also unknowingly execute malicious scripts when viewing
| dynamically generated pages based on content provided by other users.
Its not, its provided by me.
| For example, the attacker could develop an exploit that posted data to a
| different page on the legitimate web server.
Yes, but there are many variables that my script doesn't take into
consideration ... day of the week for instance.
| Solutions for Users
| None of the solutions that web users can take are complete solutions. In
| the end, it is up to web page developers to modify their pages to
| eliminate these types of problems.
Since I wrote the text file that I'm now transmitting, how does that differ
from the web server reading a text file with HTML mark up in it and sending
that out?
Please do tell me because I'm curious where the security flaw lies in this.
Taking into consideration that no mention was made of the file being
anything other than a flat text file with no HTML code in it (given that the
question asked for how to put HTML into it). Crack open the escapeHTML sub
in CGI ? Still, even if the I do nothing but copy the file from disk to
STDOUT with the content-type set as text/plain, IE will try to interpret it
as HTML. And that's a problem with this script ... ? (Paraphrased from
<http://www.apache.org/info/css-security/apache_specific.html>)
Col.
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Mon, 31 Jul 2000 23:10:56 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: text file to html
Message-Id: <Pine.GHP.4.21.0007312224580.22351-100000@hpplus03.cern.ch>
On Mon, 31 Jul 2000, Colin Keith wrote:
> Please do tell me because I'm curious where the security flaw lies in this.
You pretended the file was under _your_ control, whereas the point of
this thread was that it was really supplied by the hon. Usenaut who
posed the question.
> Taking into consideration that no mention was made of the file being
> anything other than a flat text file with no HTML code in it
That way lies madness. There was no mention of the file being
guaranteed to _not_ contain two rather important ASCII characters.
You have NOT converted the text file to HTML, except by chance and
good luck you might have given that impression in spite of the
fundamental flaw in your method. According to the excellent advice at
http://www.cert.org/tech_tips/malicious_code_mitigation.html you need
to _either_ properly convert the risky source into harmless markup
_or_ filter out/report any risky stuff that you were assured couldn't
happen.
> (given that the question asked for how to put HTML into it).
Vague though the question was, that was NOT what it
asked. Suppose the text file had been POD, for example[1]
Well, I deduced that the questioner wanted to _convert_ the file, and
their subsequent posting (on a different thread) made that clear.
You didn't convert. My evaluation is that you took potentially risky
content and inserted it into a kind of envelope which _increased_ the
risk.
I'd say that in a situation where the job has been specified in an
imprecise way, the onus is on YOU, the specialist, to take the most
conservative view and provide code that protects them against
unnecessary risk. You did the exact opposite.
> Crack open the escapeHTML sub in CGI ?
Well, actually thereby hangs a tale, as inspection of recent versions
of CGI.pm would reveal in this area. But yes, that's what the code is
for.
Although the CERT alert is worded in terms of _malicious_code_, the
fact is that this doesn't necessarily have to be malicious in order to
bite you. Earlier today I tried to view a plaintext file which the
server had accidentally sent out as text/html, and Netscape tried to
comply, which caused a Javascript error report followed by the browser
crashing. I don't believe any of this had been malicious, but it
still caused an incident.
> Still, even if the I do nothing but copy the file from disk to
> STDOUT with the content-type set as text/plain, IE will try to interpret it
> as HTML.
Right, and that's a serious security exposure in that
improperly-behaved application in some situations. But it wasn't the
issue here.
all the best.
[1]which _had_ been a specific problem with the Perlbug database web
interface at http://bugs.perl.org/perlbug.cgi
By failing to _convert_ the data to HTML, it produced nonsense from
data that contained POD markups. I'm glad to see that it seems to be
fixed now. Which makes it seem rather a pity when two contributors to
this group march up and apparently re-invent the same problem.
------------------------------
Date: Mon, 31 Jul 2000 21:33:12 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: text file to html
Message-Id: <sgmh5.63$DT4.2135971@nnrp2.clara.net>
In article <Pine.GHP.4.21.0007312224580.22351-100000@hpplus03.cern.ch>, "Alan J. Flavell" <flavell@mail.cern.ch> wrote:
>You pretended the file was under _your_ control, whereas the point of
>this thread was that it was really supplied by the hon. Usenaut who
>posed the question.
As someone who writes scripts I write them as though it is my file and I
know the contents. Since this was a suggestion as to how to the author could
copy a file and with lack of further evidence I assumed he would control the
script and the file. Not a huge leap of faith, but...
>http://www.cert.org/tech_tips/malicious_code_mitigation.html you need
>to _either_ properly convert the risky source into harmless markup
You should also note that in my posts to (one of these two threads) that my
initial reaction was to say to print it as a text file, thus ignoring any
improper characters/markup code in the file (Except in the case of IE as
agreed upon)
>asked. Suppose the text file had been POD, for example[1]
Yeah, it could already have contained HTML too. There is no definition of a
'text file' where the markup language is also text. Neither does the
definition state if it is a unicode text file, in which case the character
set that should have been returned was absent and we both should have failed
the test.
>I'd say that in a situation where the job has been specified in an
>imprecise way, the onus is on YOU, the specialist, to take the most
>conservative view and provide code that protects them against
>unnecessary risk. You did the exact opposite.
But in a place where I have the file I could examine it. In a situation
where I could not I would ask questions about its generation/content. I
suppose a degree of trust was involved that 'text file' means a file without
markup, etc.
*hangs his head and feels chastised*
You are right though. Thank you for pointing it out:)
Of course, this is why you're being paid (at least) twice what I am? :)
Col.
(PS - Do I call you master Yoda now? :-)
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: Mon, 31 Jul 2000 14:21:52 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: tricky regexp
Message-Id: <3985EDF0.553AB728@ipac.caltech.edu>
Tarjei Vassbotn wrote:
> > ... given a string
> > that contains an arbitrary name encapsulated by underscores (eg
> > "lorem _ipsum_ dolor"), the substring "_ipsum_" would need to be
> > replaced by the value of the perl variable $ipsum ...
>
> ...
> my $text='lorem _ipsum_ dolor';
> my %replacers=(ipsum => 'REPLACED');
> $text=~ s/_([^_]+)_/$replacers{$1}/g;
> print $text; # prints 'lorem REPLACED dolor'
Tarjei's solution looks best to me, but FYI, you could also use the 'e'
flag:
my $a="some _text_ to _play_ with";
my ($text,$play)=("stuff","mess");
$a=~s/_([^_]+)_/"\$$1"/eeg;
print $a; # Produces "some stuff to mess with"
Note that depending on details you haven't mentioned you may want the RE
to include whitespace around the underscores -- i.e. '/\s+_([^_]+)_\s+/'
-- and you may want to restrict the contents of the identifier to those
allowed for perl variables excluding '_' -- i.e.
'/\s+_((?:[a-zA-Z][a-zA-Z0-9])+))_\s+/'. Neither of these are necessary,
just something to think about.
--
-- Tim Conrow tim@ipac.caltech.edu 626-395-8435
------------------------------
Date: 31 Jul 2000 21:43:18 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: tricky regexp
Message-Id: <8m4rtl$5mcr3$7@ID-24002.news.cis.dfn.de>
hi,
Tim Conrow <tim@ipac.caltech.edu> wrote:
> Tarjei Vassbotn wrote:
>> > ... given a string
>> > that contains an arbitrary name encapsulated by underscores (eg
>> > "lorem _ipsum_ dolor"), the substring "_ipsum_" would need to be
>> > replaced by the value of the perl variable $ipsum ...
>>
>> ...
>> my $text='lorem _ipsum_ dolor';
>> my %replacers=(ipsum => 'REPLACED');
>> $text=~ s/_([^_]+)_/$replacers{$1}/g;
>> print $text; # prints 'lorem REPLACED dolor'
> Tarjei's solution looks best to me, but FYI, you could also use the 'e'
> flag:
> my $a="some _text_ to _play_ with";
> my ($text,$play)=("stuff","mess");
> $a=~s/_([^_]+)_/"\$$1"/eeg;
> print $a; # Produces "some stuff to mess with"
but be careful and don't do this if $a comes from
user input. imagine this:
my $a="some _var=`rm -r /`_ to delete your harddrive";
better use a hash as it was said before.
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please no answers via email unless followup is set to poster.
------------------------------
Date: Mon, 31 Jul 2000 22:46:03 +0200
From: Luc-Etienne Brachotte <Luc-Etienne.Brachotte@wanadoo.fr>
Subject: Re: ttt
Message-Id: <3985E58B.9BB18828@wanadoo.fr>
!!!
Jimmy Lantz a écrit :
> Œ* Œ* Œ*£°
> ttt”– **¥“‚Àº?
>
> Xin Li wrote:
> >
> > ttt
------------------------------
Date: Mon, 31 Jul 2000 20:03:25 GMT
From: oliver.arend@gmx.de
Subject: Uploading images via Perl script
Message-Id: <8m4m29$dmo$1@nnrp1.deja.com>
Hi there,
I guess you've seen the possibility to upload images onto a server via
a Perl script, e.g. in a discussion forum.
Can anyone give me a script that will do exactly this, w/ explanations
how it works?
Oliver
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 31 Jul 2000 16:07:48 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Uploading images via Perl script
Message-Id: <8m4pr4$84j$1@provolone.cs.utexas.edu>
In article <8m4m29$dmo$1@nnrp1.deja.com>, <oliver.arend@gmx.de> wrote:
>Hi there,
>
>I guess you've seen the possibility to upload images onto a server via
>a Perl script, e.g. in a discussion forum.
>
>Can anyone give me a script that will do exactly this, w/ explanations
>how it works?
There may be some example code in the documentation.
Try "perldoc CGI". The CGI module supports uploading of files. If you
don't have CGI on your system, you should be able to get it from
http://www.perl.com/CPAN/ .
Hope that helps.
- Logan
------------------------------
Date: Mon, 31 Jul 2000 20:14:36 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: Use MIME *and* specify the mail server
Message-Id: <M6lh5.59$DT4.2125060@nnrp2.clara.net>
In article <8m4cm1$5lt$1@nnrp1.deja.com>, mfreake@iii.co.uk wrote:
>I'm quite new to Unix mail systems which may be the cause of the
>problem.
>
>I want to attatch some files to an email *and* specify the mail server
>to be used (mail3.ourdomain.co.uk, for a made up example).
>
>My previous uses of MIME::Entity used ordinary sendmail which I cannot
>see how you specify the server with. Normally to specify the server I
You don't specify a server with an MTA. That's why domains have MX records -
Mail Exchanges - Hosts that will handle mail for the domain. They will each
have a preference and each will be tried in order of preference to allow the
mail to be transfered even if a host is down. You can use source routing by
defining the path the mail should take using % symbols, but most places
these days will bounce mails like this as the 'percentage hack' as it is
known is often exploited to force a mail server to route mail that it
wouldn't otherwise handle. Best exploited by spammers, etc.
If you wish to deliver directly to a machine you will need to build a
connection yourself (or find a program that will allow you to specify one)
It is unnatural to want to do this though as email is sent to a domain and
it is up to the administrators of that domain to dictate which machines they
want to handle the mail, not up to you to try and force it in via a
particular machine.
>use Fido::Sendmail which seems either won't take the resulting
>MIME::Entity as body (not surprisingly, it's an object not plain text)
>or if I stringify the text it just sends the mail as ugy plain text
>(all that "This is a multi-part message in MIME format... stuff" and no
>attatched files)
>
>Am I being really dense here ? Any help v.gratefully accepted.
Urm, urm, someone posted the answer to this stuff the other day, its
something along the lines of using Mail::* and MIME::* I can't see the exact
post I was thinking of but look up <3976D8A3.52347696@schmic.com> on
dejanews (that's the first article in the thread asking a similar question
to yours)
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
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 3863
**************************************