[22180] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4401 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 14 14:06:21 2003

Date: Tue, 14 Jan 2003 11:05:11 -0800 (PST)
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, 14 Jan 2003     Volume: 10 Number: 4401

Today's topics:
        Checking XML for validity (Bob Dubery)
    Re: Checking XML for validity (Tad McClellan)
    Re: command-line args style flags from a file (Ben Morrow)
    Re: command-line args style flags from a file (Kevin Newman)
    Re: comment multiple lines (Tad McClellan)
    Re: comment multiple lines <spikey-wan@bigfoot.com>
    Re: finding largest repeat values in array ctcgag@hotmail.com
        Flushing the Output Stream <chuck.carson@syrrx.com>
    Re: Flushing the Output Stream (Anno Siegel)
    Re: Flushing the Output Stream <nobull@mail.com>
    Re: Flushing the Output Stream <chuck.carson@syrrx.com>
    Re: Flushing the Output Stream <chuck.carson@syrrx.com>
    Re: Flushing the Output Stream <uri@stemsystems.com>
    Re: Flushing the Output Stream (Anno Siegel)
    Re: How to delete leading&trailing spaces&tabs at once? <a@b.c>
    Re: How to execute a perl script from within a perl scr <nobull@mail.com>
    Re: How to execute a perl script from within a perl scr (Pete)
    Re: IFRAME and Cookies <nobull@mail.com>
    Re: IFRAME and Cookies <mbudash@sonic.net>
    Re: My, our, etc. <spikey-wan@bigfoot.com>
    Re: My, our, etc. <spikey-wan@bigfoot.com>
    Re: My, our, etc. (Ben Morrow)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 14 Jan 2003 15:28:39 GMT
From: megapode@hotmail.com (Bob Dubery)
Subject: Checking XML for validity
Message-Id: <3e242b85.98518312@10.100.2.1>

Hi all,

XML::DOM checks XML for well-formedness during it's inital parsing of
the input XML file. However, it doesn't check to see if the actual
contents of the file correspond to the DTD.

As I understand it XML::DOM uses XML::Parser for the actual parsing of
the file, so it's XML::Parser that isn't checking to see if the file
corresponds to the DTD. That would also mean that several other XML
processing modules would not make that check.

Is there a Perl module that checks XML for validity and not just
well-formedness?


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

Date: Tue, 14 Jan 2003 10:01:49 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Checking XML for validity
Message-Id: <slrnb28d3d.7jn.tadmc@magna.augustmail.com>

Bob Dubery <megapode@hotmail.com> wrote:

> Is there a Perl module that checks XML for validity and not just
> well-formedness?


   http://search.cpan.org/search?query=ValParser&mode=all


There is also a mailing list specifically for XML processing
using Perl, which is where the module above was brought to
my attention:

   http://listserv.ActiveState.com/mailman/listinfo/perl-xml


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 14 Jan 2003 16:45:52 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: command-line args style flags from a file
Message-Id: <b01es0$1h5$1@wisteria.csv.warwick.ac.uk>

knewman00@earthlink.net (Kevin Newman) wrote:
>mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow) wrote in message news:<avt2o9$1ms$1@wisteria.csv.warwick.ac.uk>...
[lots of snippage]
>> 
>> Would something like: [untested and incomplete code]
>> 
>> use Getopt::Std;
>> use constant options => 'cbf:o:';
>> 
>> getopts(options . 'L:', \my(%cmd_opts));
>> my $file = delete $cmd_opts{L};
>> unless($file) {
>>   process_options(%cmd_opts);
>> }
>> else {
>>   open my $CONFIG, "<", $file;
>>   for my $opts (<$CONFIG>) {
>>     @ARGV = split ' ', $opts;
>>     getopts(options, \my %file_opts);

** (see below)

>>     my %all_opts = (%cmd_opts, %file_opts);
>>     process_options(%all_opts);
>>   }
>> }
>> 
>> be what you're looking for? The basic idea is to add each set of options
>> from
>> the file to those given on the command line, then process the whole set.
>
>Nice....
>I'm always learning new syntax, so could you explain a few statements
>in your code?

Sure :)

>1. Why use constants?

use constants options => 'cbf:o:';
creates a sub called options that just returns the string 'cbf:o:'. It is
declared with a special prototype that means you never need to call it as
options(): the compiler knows it takes no arguments, so won't try to give it
any. It's basically the same as saying
my $options = 'cbf:o:';
and replacing all occurences of options with $options, except that the 
optimizer will try and inline the constant at compile time (because it knows
it's always constant).

> 2. Why options . 'L:'?

The options string defined at the top contains all the options you want to 
allow from out of a file. From the command line, you want an extra option, -L,
to specify a file to read (I presume you don't want to allow -L in a config 
file? That could get highly confusing :). So this means that the command-line
options will be processed for 'cbf:o:L:' whereas the options read from the file
will just be processed with 'cbf:o:', but the option list is only specified in
one place (at the top). This is in general a good idea... if things are 
supposed to be the same, make sure the computer knows that :)

> 3. Why do you have to do
>(%cmd_opts, %file_opts)?

This will take the options specified on the command line (minus -L), and 
combine them with the options you just read out of the file. The reason I put
this in was that in your OP you gave the example

>> >myscript.pl -f<inputfile> -L do_flags.txt

where (presumably) -f <inputfile> should be added to each set of flags read
from the file before processing.


The way this works (I'm not sure if you understand this or not: sorry if I'm
being patronising :) is that a hash evaluated in list context returns a list
(key, value, key, value, ...) so that list there will have all the keys and all
the values from both hashes. When that is assigned to %all_opts it will
reconstitute them into key/value pairs within the hash.

With them in that order, options from out of the file will override the same 
option from the cmd line: if you want it the other way round, reverse them.

>  Any suggestions on how to do a "soft error
>trap within the loop (see the unfinished but tested code below)? 
>Let's suppose there are 10 lines of commands in a file, but line 3 an
>8 are incorrectly formatted (use -Y flag).  How can I by pass that
>"bad line" and continue processing.

Hmm, this is tricky :)
getopts will stop processing @ARGV when it hits something that doesn't look
like a switch, so inserting

if (@ARGV) {
  print STDERR "Line $. of $file is invalid\n";
  next;
}

where I have put ** above will check for that. ($. is the current line of the
last filehandle accessed: perldoc perlvar).

To die gracefully if the file gives an unknown flag is a little harder, though,
as getopts just warns in that case.... I 'spec the only answer might be to 
replace the getopts line with

eval {
  local $SIG{__WARN__} = sub { die shift; };
  getopts(options, \my %file_opts);
  local $" = ", ";
  die "Extra rubbish after switches: @ARGV" if @ARGV;
}
if($@) {
  (my $err = $@) =~ s/(at .* line \d+.\s*)*//;
  handle_error($err);
  next;
}

which is kinda complex :)

To go through it:

The eval sets up an exception-trapping block: any calls to die within that
block won't actually stop the program, they will put the message it died with
into $@ and jump straight out of the eval. $@ is guaranteed to be undef if
nothing dies inside the eval.

The $SIG{__WARN__} makes all warnings into die()s, so if getopts warns about
unknown options you will drop straight out of the eval. The local() means that 
warnings will go back to being warnings after the eval is over.

The getopts call is as before.

The local $" = ", " makes it so (until the end of the eval) arrays interpolated
into strings will have ", " added between each element. Otherwise you get no
separator at all, which can be confusing.

Then the die will jump out of the eval if there are any args left in the line
read from the file, telling you what they are.

if($@) checks if anyone died inside the eval. If they did:

$err is set to $@ minus any rubbish about where the die happened. You may want
to leave this bit out: I tend to put it in if I'm going to print a message to
an end-user as they don't really want to know where in the script the message
is coming from. OTOH, it can make debugging harder...

handle_error is called, with the error message. You can do what you like in
here (well, really :). It may be better to move the s/// line inside here:
check if $_[0] =~ /Unknown option/ or $_[0] =~ /Extra rubbish/ and if it
doesn't, call warn normally (so you get any other warnings). Then strip the
rubbish and tell the user (or do nothing, or whatever...).

next; will go back to the top of the for() loop to read the next line from the
file.

Ben


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

Date: 14 Jan 2003 10:39:26 -0800
From: knewman00@earthlink.net (Kevin Newman)
Subject: Re: command-line args style flags from a file
Message-Id: <4c8e4398.0301141039.2c5c64a2@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb27aag.5ma.tadmc@magna.augustmail.com>...
> Kevin Newman <knewman00@earthlink.net> wrote:
> > "Harald H.-J. Bongartz" <bongie@gmx.net> wrote in message news:<1601609.3xdfVSxWaW@nyoga.dubu.de>...
> >> Kevin Newman wrote:
> >> > I have code that works for input from the command-line (using
> >> > Getopt::Std).  I've even made an attempt at getting the arguments to
> >> > work from a file.
>  
> >> You can use Getopt::Std for that, too.  Just read the lines from your
> >> do_flags.txt into @ARGV, line by line:
>  
> >>           @ARGV = split;
>  
> >> Of course, when using this trivial method you won't get the quoting
> >> capabilities of the shell, i.e. your do_flags.txt should not contain
> >>         -c -o "Output File With Blanks.o"
> >> or something like that.
> 
> 
> > I like this too (see the reply to Ben Morrow).  BTW, can you describe
> > a non trivial method to handle filenames with spaces?  
> 
> 
> That is a Question that is Asked Frequently:
> 
>    perldoc -q split
> 
>       How can I split a [character] delimited string except when
>       inside [character]?
> 
> 
> Using the module suggested there:
> 
>    use Text::ParseWords;
>    @ARGV = quotewords(q/ /, 0, $_);
> 
> or, even more non-trivially :-) you could do this
> 
>    @ARGV = grep {defined and length} split /(?:"([^"]+)")|\s+/;
> 
> Rather too much job security in that second one though,
> so use the module instead.


I've seen this in the split FAQ before and just by-passed it because I
didn't need it... ummmm, at the time. :-)
Good, I'll give grep and Text::ParseWords a try.

Thanks,

kln


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

Date: Tue, 14 Jan 2003 08:13:42 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: comment multiple lines
Message-Id: <slrnb286om.6eo.tadmc@magna.augustmail.com>

Brian McCauley <nobull@mail.com> wrote:
> ZZT <a@b.c> writes:

[snip yet another FAQ]

> In case it had eascaped your notice, you are expected to consult the
> FAQ _before_ you post.


Don't be so silly.

ZZT's time is important!

Everyone else's time is not important.


-------------------------------
   "Just what we need, another Newsgroup Nazi."
   Message-ID: <sg3d8u80fi1hg13r9iekv780jrrssigo4l@4ax.com>

   "He was rude and didn't give any help"      (pot, kettle, black)
   Message-ID: <kovi8u0ah2p1jpvu4pk9fcna4cfv8thiq1@4ax.com>

   "Is there a kind of sleep or wait function?"  (SAQ)
   Message-ID: <asqabk$8kd$1@news1.wdf.sap-ag.de>

   "is there a way to read a value from standard-input (keyboard)
    with one command"
   Message-ID: <asq7rp$6je$1@news1.wdf.sap-ag.de>

   "how can I simulate a telnet session to a specific port in perl"
   Message-ID: <aprs5f$1ij$1@news1.wdf.sap-ag.de>

   "is there a not to difficult way to retrieve+delete mails
    from an IMAP server within a perl-script?"
   Message-ID: <apr6iv$ete$1@news1.wdf.sap-ag.de>

   "Is there a way to make such an ass. array clearer?"  (SAQ)
   Message-ID: <al7nbd$bu9$1@news1.wdf.sap-ag.de>

   "I have a line with the following format (undefined spaces
    between the entries) and would like to extract the value"
   Message-ID: <al7f1i$623$1@news1.wdf.sap-ag.de>

   "a way to open a file and set the readposition without reading
    the whole file"
   Message-ID: <al76vr$jp$1@news1.wdf.sap-ag.de>

   "I have $string="xxx/STRING.yyy" and would like to extract
    STRING while xxx can be anything"
   Message-ID: <ag1jab$sh3$1@news1.wdf.sap-ag.de>

   "Now I want to get the string xxx (length not defined) in a $value."
   Message-ID: <afrjat$ogr$1@news1.wdf.sap-ag.de>

   "exists a substring in a string"  (SAQ)
   Message-ID: <ag1ga9$q28$1@news1.wdf.sap-ag.de>

   "I would like to give the perl-script some startup-parameters.
    How can I access them inside the script?"
   Message-ID: <afs2cf$6k1$1@news1.wdf.sap-ag.de>

   "How to generate the next foreach loop?" (SAQ)
   Message-ID: <3CC6D363.8050402@b.c>

   "How to find out, how many elements an array has?"
   Message-ID: <3CC14B8A.80007@b.c>

   "a simple routine that tells me if for instance "file1* exists"
   Message-ID: <3C9F1ADD.1090903@b.c>

   "I call perl with the script and some parameters. How can I
    get these parameters inside the script?"
   Message-ID: <3C99F165.40003@b.c>

   "with $string=~ s/string1/string2/; I can replace the 1st
    occurence of string1 in $string. Is there a way to replace all?"
   Message-ID: <3C875646.5070903@b.c>

   "switch/case question"
   Message-ID: <3C80D6A2.4070402@b.c>

   "execute an external program and would like to get the output
    of this program in a @-variable. How can I do that?"
   Message-ID: <3C7F30F9.9050505@b.c>

   "is there a way to split a string by another string?"  (SAQ)
   Message-ID: <3C7CA93D.6000408@b.c>

   "is that possible? I have string "6.23" and want to get "6,23"."
   Message-ID: <3C4ED5F8.8010403@b.c>

   "i c/c++ you can comment out multiple line by using /*   ...  */ (FAQ)
    Is there something comparable in perl?"
   Message-ID: <b011cd$pik$1@news1.wdf.sap-ag.de>


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 14 Jan 2003 14:31:35 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: comment multiple lines
Message-Id: <b0171q$457$1@newshost.mot.com>


"ZZT" <a@b.c> wrote in message news:b011cd$pik$1@news1.wdf.sap-ag.de...
> Hi all,
>
> i c/c++ you can comment out multiple line by using /*   ...  */
> Is there something comparable in perl?
>
> thanks

Use a decent editor that allows you to comment out blocks of code. I like
Crimson editor.

R.




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

Date: 14 Jan 2003 16:42:33 GMT
From: ctcgag@hotmail.com
Subject: Re: finding largest repeat values in array
Message-Id: <20030114114233.637$xp@newsreader.com>

Andrew Lee wrote:
> On 13 Jan 2003 16:52:43 GMT, ctcgag@hotmail.com wrote:
>
> >Andrew Lee wrote:
> >> On 07 Jan 2003 16:44:36 GMT, ctcgag@hotmail.com wrote:
> >>
> >> >hugo <hugo@geoinformex.com> wrote:
> >> >> Hi
> >> >>
> >> [question snipped]
> >>
> >> >You need to reset repeat, and capture the greatest value.
> >> >
> >> >my $most=-1;
> >> >my $repeat=1;
> >> >for my $i (1..@myArray) {
> >> >  if (myArray[$i] eq myArray[$i -1]) {
> >> >     $repeat++;
> >>
> >> Ack!!!
> >>
> >> That won't work unless you have reset $[ (a soon to be deprectaed
> >> "feature").
> >
> >Other than the missing $s, which $[ won't affect, why won't it work?
>
> Ok.  But, it will give a warning.
>
> I am particularly wary of running past the end of an array. (old C
> habits never die).

OK, you're right, it won't (necessarily) work.  I thought you were
complaining about the *other* end of the range.  I also forgot to
deal with 1-member arrays.  (of course, it still doesn't deal with
zero member arrays properly.)

my $most=1;
my $repeat=1;
for my $i (1..$#myArray) {
  if ($myArray[$i] eq $myArray[$i -1]) {
     $repeat++;
  }
  else {
     $most=$repeat if $repeat>$most;
     $repeat=1;
  };
};

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Tue, 14 Jan 2003 09:35:24 -0800
From: Chucky <chuck.carson@syrrx.com>
Subject: Flushing the Output Stream
Message-Id: <3E244A5C.6090506@syrrx.com>


I have a script that inserts upwards of 10 million rows into Oracle per 
data load. I want to display a status indicator for each record based on 
the file type, ex:

 ......dddlllll.....d..... etc....

However, it does it in odd chunks. Is there a way to print each one as 
it is actually processed? I seem to remember tweaking this years ago for 
some other scripts.

Thanks,
CC



-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
   http://www.newsfeed.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----


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

Date: 14 Jan 2003 17:35:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Flushing the Output Stream
Message-Id: <b01hpe$jnm$6@mamenchi.zrz.TU-Berlin.DE>

Chucky  <chuck.carson@syrrx.com> wrote in comp.lang.perl.misc:
> 
> I have a script that inserts upwards of 10 million rows into Oracle per 
> data load. I want to display a status indicator for each record based on 
> the file type, ex:
> 
> ......dddlllll.....d..... etc....
> 
> However, it does it in odd chunks. Is there a way to print each one as 
> it is actually processed? I seem to remember tweaking this years ago for 
> some other scripts.

    $| = 1;

See perlvar for $|.

Anno


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

Date: 14 Jan 2003 18:27:10 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Flushing the Output Stream
Message-Id: <u9n0m3ege9.fsf@wcl-l.bham.ac.uk>

Chucky <chuck.carson@syrrx.com> writes:

> Subject: Flushing the Output Stream

This is FAQ: "How do I flush [...] an output filehandle? [...]"

Good manners require that you consult the FAQ _before_ you post a
question.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 14 Jan 2003 10:39:02 -0800
From: Chucky <chuck.carson@syrrx.com>
Subject: Re: Flushing the Output Stream
Message-Id: <3E245946.9000902@syrrx.com>


This was very amusing.

If you are going to waste bandwidth, at least post the answer. What do 
you think newsgroups are for, actually finding a question or problem 
that is absolutely not covered in any of the hundreds of books or FAQ's? 
No. It is for quick dialogs between persons that share common interests.

Since I develop in 5 different languages on a daily basis I was looking 
for a quick answer from someone whi is not as rusty as I am at the 
moment. At least the group was helpfull 10 years ago when I first 
started using it.

Take your negativeness elsewhere and grow up.



Brian McCauley wrote:
> Chucky <chuck.carson@syrrx.com> writes:
> 
> 
>>Subject: Flushing the Output Stream
> 
> 
> This is FAQ: "How do I flush [...] an output filehandle? [...]"
> 
> Good manners require that you consult the FAQ _before_ you post a
> question.
> 



-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
   http://www.newsfeed.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----


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

Date: Tue, 14 Jan 2003 10:41:44 -0800
From: Chucky <chuck.carson@syrrx.com>
To: Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
Subject: Re: Flushing the Output Stream
Message-Id: <3E2459E8.2040108@syrrx.com>



Much thanks kind sir. Actually used less bandwidth than the other nitwit 
who replied.

Thanks again.
CC

Anno Siegel wrote:
> Chucky  <chuck.carson@syrrx.com> wrote in comp.lang.perl.misc:
> 
>>I have a script that inserts upwards of 10 million rows into Oracle per 
>>data load. I want to display a status indicator for each record based on 
>>the file type, ex:
>>
>>......dddlllll.....d..... etc....
>>
>>However, it does it in odd chunks. Is there a way to print each one as 
>>it is actually processed? I seem to remember tweaking this years ago for 
>>some other scripts.
> 
> 
>     $| = 1;
> 
> See perlvar for $|.
> 
> Anno



-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
   http://www.newsfeed.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----


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

Date: Tue, 14 Jan 2003 18:51:11 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Flushing the Output Stream
Message-Id: <x77kd7pntt.fsf@mail.sysarch.com>

>>>>> "C" == Chucky  <chuck.carson@syrrx.com> writes:

  C> If you are going to waste bandwidth, at least post the answer. What
  C> do you think newsgroups are for, actually finding a question or
  C> problem that is absolutely not covered in any of the hundreds of
  C> books or FAQ's? No. It is for quick dialogs between persons that
  C> share common interests.

if you think usenet is fir quick dialogs, you are sadly mistaken. news
can still take hours and days to propogate around the net. usenet is for
discussion and not for immediate urgent help.

  C> Since I develop in 5 different languages on a daily basis I was
  C> looking for a quick answer from someone whi is not as rusty as I am
  C> at the moment. At least the group was helpfull 10 years ago when I
  C> first started using it.

and have you forgotten where the docs and FAQ are located?

  C> Take your negativeness elsewhere and grow up.

and you aren't negative? pot, meet kettle.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class


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

Date: 14 Jan 2003 19:00:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Flushing the Output Stream
Message-Id: <b01mo4$r52$1@mamenchi.zrz.TU-Berlin.DE>

Chucky  <chuck.carson@syrrx.com> wrote in comp.lang.perl.misc:
> 
> 
> Much thanks kind sir. Actually used less bandwidth than the other nitwit 
> who replied.

I'll have you know that, as far as Usenet goes, I consider that nitwit
a friend.  I might have said what he said.  I didn't for no more particular
reason than getting tired of saying it.

I also note that your reply is top-posted and full-quoted, despite your
alleged long-standing acquaintance with Usenet.  So long.

Anno


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

Date: Tue, 14 Jan 2003 15:56:21 +0100
From: ZZT <a@b.c>
Subject: Re: How to delete leading&trailing spaces&tabs at once?
Message-Id: <b018el$24c$1@news1.wdf.sap-ag.de>

Tad McClellan wrote:

> It works fine. There is something else going on that you 
> haven't told us.

in case that tabs are "around" the space this didn't work, because the 
tabs are removed after the space

\t\s\s\sHello\s\s\t\t

but using [\t ] as you can see in the other reply works good

bye



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

Date: 14 Jan 2003 18:10:53 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to execute a perl script from within a perl script and return info
Message-Id: <u9wul7eh5e.fsf@wcl-l.bham.ac.uk>

"Anders Torvill Bjorvand" <torvill@trolldata.no> writes:

> This is the simplified code

When you say "simplified code" do you mean that you have simplified
the code on your computer, confirmed that it still reproduces the
problem you describe?

Or do you mean that you are not showing us all of the script?

If a script is displaying behaviour you don't understand then you are
not the best person to judge which bits of the script one needs to see
to understand the behaviour.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 14 Jan 2003 10:59:30 -0800
From: falconflyr@snet.net (Pete)
Subject: Re: How to execute a perl script from within a perl script and return info
Message-Id: <4ca21189.0301141059.5d946602@posting.google.com>

In a.cgi, if instead of:

print $content;

 . . . you do this:

system("/home/www/myserver/mydir/b.cgi");

 . . . b.cgi would get executed from a.cgi and when b.cgi is done
control
would be returned to a.cgi for further processing if needed.  I call
other
Perl scripts from iside Perl scripts like this all the time.  You
could also make b.cgi a subroutine in a.cgi, maybe.  Hope this helps.


Andras Malatinszky <nobody@dev.null> wrote in message news:<3E240769.3060305@dev.null>...
> Anders Torvill Bjorvand wrote:
> 
> > This is the situation:
> > 
> > I have two scripts a.cgi and b.cgi residing the following places on the
> > server:
> > /home/www/myserver/a.cgi
> > /home/www/myserver/mydir/b.cgi
> > 
> > Both scripts are executable (755).
> > 
> > This is the simplified code of a.cgi:
> > ------------
> > #!/usr/bin/perl
> > $content = `/home/www/myserver/mydir/b.cgi`;
> > 
> > print "Content-type:text/html\n\n";
> > print $content;
> > 
> > exit;
> > ------------
> > 
> > This is the simplified code of b.cgi:
> > ------------
> > #!/usr/bin/perl
> > 
> > print "Content-type:text/html\n\n";
> > print "This is the output from b";
> > 
> > exit;
> > ------------
> > 
> > When running a.cgi, it should produce the output from b.cgi, but a.cgi
> > outputs nothing.
> > 
> > Changing line 2 in a.cgi to:
> > $content = ` perl /home/www/myserver/mydir/b.cgi`;
> > does not seem to change anything.
> > 
> > Why doesn't this work, and how can I get it to work?
> > 
> > Sincerely,
> > Anders T. B.
> > 
> 
> This is just a guess, but check the permissions of mydir. I assume this 
> is all in a CGI context, and the user your a.cgi is running as may not 
> have read permissions to the mydir directory. See if moving b.cgi up one 
> level into the myserver directory changes things.
> 
> Of course our guesses could be more educated if you asked perl to help 
> you with things like error checking.


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

Date: 14 Jan 2003 18:06:06 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: IFRAME and Cookies
Message-Id: <u91y3ffvxt.fsf@wcl-l.bham.ac.uk>

"Frode Bjerkholt" <fb@geo-guide.com> writes:

> "Brian McCauley" <nobull@mail.com> wrote in message
> news:u9znq3j2a7.fsf@wcl-l.bham.ac.uk...
> > "Frode Bjerkholt" <fb@geo-guide.com> writes:
> >
> > > I have made a CGI-script in Perl,
> >
> > What makes you think that the "in Perl" bit is relevant to your
> > problem?  You have a question about the circumstances under which a
> > HTTP client will include cookies in an HTTP request.  Do you really
> > think this will depend on the language you used to write scripts on
> > the HTTP server?
> 
> Not really, but I must admit that I find it quite amusing that you actually
> commented it :-)

You find someone trying to help you by telling you that that you have
totally mis-identified the domain of your problem is amusing?  The
fact that you think your problem is something to do with Perl means
you are looking for solutions in the wrong place.  I thought this
information may help you.

> Annoying isn't it?

Yes off-topic post(er}?s are annoying.  Post off-topic repeatedly or
attempt to defend off-topic posting and some of people here will stop
reading your posts.  When you do have a Perl question this means you
will loose out on the chance to have it looked at by experts because
some of the best experts here are real plonkers! :-)

> > > If this HTML document is located on the same server as the CGI-script, it
> > > works fine.......but if the HTML document is located on a different
> > > host [...] the script never gets any cookies from the browser.
> >
> > Make sure your cookies are tied to a domain suffix not a specific
> > host.  This, of course, pre-supposes that the two servers have a
> > common domain suffix.  (Note: the common suffix must be more than just
> > a TLD).
> 
> That is a problem. The two servers, do not have a common domain suffix.
> So I guess I am stuck then?

My understanding is that if you want to be able to set a cookie on one
server and use it on another then then servers mush have a common
domain suffix.

I'm not an expert in this particular field.  Perhaps if you took this
question to a newgroup where is was on-topic (perhaps one related to
web issues) then you might find more experts.

> Here is some additional information, to help clarify the situation:
> 
> The reason for using IFRAME, is that I do not want to have anything do with
> content of the web-pages on the other server.
> The owners of this remote server should only input the IFRAME tag into one
> of their HTML-page and be able to use my CGI-based service without bothering
> anything more about it.

So it sounds to me like you are _not_, after all, trying to set
cookies from one server an use them on the other.  In this case the
lack of a common suffix shouldn't matter.

> This remote server belong to a larger domain. The
> server running my CGI-based service do not belong to any named domain. It
> has only got a static IP-address.

AFAIK HTTP severs addressed by IP addresses can't use cookies at all.
But then, like I say, I'm not a cookie expert and this isn't really
the place to look for them.

[ snip untrimmed tail-qoute including my .sig ]

Please don't do that (it's rude).

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 14 Jan 2003 18:09:19 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: IFRAME and Cookies
Message-Id: <mbudash-D52AA2.10091914012003@typhoon.sonic.net>

In article <QhTU9.13463$Rc7.209427@news2.e.nsc.no>,
 "Frode Bjerkholt" <fb@geo-guide.com> wrote:

> Hi
> 
> I have made a CGI-script in Perl, that is using cookies. The script is
> lauched as a IFRAME in a HTML document.
> If this HTML document is located on the same server as the CGI-script, it
> works fine.......but if the HTML document is located on a different host -
> as is my intension - the script never gets any cookies from the browser.

here's a hack snippet that you can start with that may help:

<script>
document.write("<iframe 
src=http://www.remoteserver.com/cgi-bin/remotescript.cgi?_cookie_=" + 
document.cookie + " frameborder=1 width=500 height=300>\n</iframe>\n");
</script>

your remote script will then "see" the cookie contents, just not as a 
cookie... of course, scripting must be enabled, but that's way i call it 
a hack...

> Is there anyway that this can be fixed...or is it this way because of
> security reasons?

you got it - security reasons...

hth-


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

Date: Tue, 14 Jan 2003 14:07:09 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: My, our, etc.
Message-Id: <b015k0$3em$1@newshost.mot.com>

Phew! :-) I think I get it, now, but I don't think I could explain it.

Could I do this?
 i.e. if asked about saving, it does if you type "yes", but if you nip to
the loo, it saves automatically.

use strict;
use warnings;

my $save = "yes";

&part_one;
&part_two;
exit;

sub save {
   save results;
}

sub part_one (
   my $save = "frogs";
  print "French people serve $save legs in restaurants.\n";
}

sub part_two {
   do stuff
   ...
   if (chomp<STDIN> eq "carry on while I go to the loo") {return};
   ...
   print "Do you want to save when finished?\n";
   $save = chomp<STDIN>;
}

END (
   if $save eq "yes" {&save}
   exit;
}

Thanks.

R.




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

Date: Tue, 14 Jan 2003 14:29:27 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: My, our, etc.
Message-Id: <b016tr$44g$1@newshost.mot.com>

This is why I started using our in the first place.
If you use my here, then you don't get any wine, only cheese ;-)

use strict;
use warnings;
# our $variable = "cheese";
my $variable = "cheese";
open (save_it, ">save.txt");
print save_it "\$variable = \"wine\";\n";
close (save_it);
do "save.txt";
print "\$variable = $variable\n";

I have about 25 variables that I want to store in a file, so each time you
run my script, you have the data you entered last time. I also give the user
the option to save, and reload the saved values.

I have save and reload subroutines. The save one consists of 25 lines like
this:

print save_it
   "\$var1 = \"one\";\n".
   "\$var2 = \"two\";\n".
   "\$var3 = \"three\";\n";

The reload routine's nice and easy:

do "save.txt" if -e "save.txt";

So, if I'm to stop using our, I need a better way of saving my variables,
please.

Thanks.

R.

PS. It may be a good idea to cc my email address with your reply, just in
case.




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

Date: Tue, 14 Jan 2003 16:00:24 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: My, our, etc.
Message-Id: <b01c6o$t46$1@wisteria.csv.warwick.ac.uk>

"Richard S Beckett" <spikey-wan@bigfoot.com> wrote:
>This is why I started using our in the first place.
<snip>
>I have about 25 variables that I want to store in a file, so each time you
>run my script, you have the data you entered last time. I also give the user
>the option to save, and reload the saved values.
>
>I have save and reload subroutines. The save one consists of 25 lines like
>this:
>
>print save_it
>   "\$var1 = \"one\";\n".
>   "\$var2 = \"two\";\n".
>   "\$var3 = \"three\";\n";
>
>The reload routine's nice and easy:
>
>do "save.txt" if -e "save.txt";
>
>So, if I'm to stop using our, I need a better way of saving my variables,
>please.

Storable.pm. Get it off CPAN if you don't have it.
Writing file out to 'do' later is tres dodgy.

Ben


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 4401
***************************************


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