Sorry for bothering everyone again, but could someone tell me what to change
so that I can import variables from external files and get them to work in
the current file?  (see original message)

Thank you,
Kyle

----- Original Message -----
From: "Kyle Babich" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 03, 2002 11:07 AM
Subject: Re: 2 Questions


> Still getting the same problem, name requires explicit package name.
>
> #!/usr/bin/perl -wT
> use strict;
> use Data::Dumper;
> use CGI qw( :standard );
>
> print header ( "text/html" );
>
> my $hash_ref = do ( 'fried.dat' ) || die "error:  unable to open
> fried.txt\n";
>  print Dumper $hash_ref;
>
> print <<"EndOfHTML";
>
> our($name); chicken
>
> EndOfHTML
>
>
>
>
> fried.dat:
>
> {
>  name => 'fried'
> }
>
>
> ----- Original Message -----
> From: "Nikola Janceski" <[EMAIL PROTECTED]>
> To: "'Kyle Babich'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Cc: "beginners-cgi" <[EMAIL PROTECTED]>
> Sent: Wednesday, July 03, 2002 9:25 AM
> Subject: RE: 2 Questions
>
>
> > scoping!!! my only scopes the end of the file!
> >
> > so my in fried.dat is scoped only in fried.dat.
> >
> > use our($name);
> >
> > > -----Original Message-----
> > > From: Kyle Babich [mailto:[EMAIL PROTECTED]]
> > > Sent: Wednesday, July 03, 2002 9:19 AM
> > > To: [EMAIL PROTECTED]
> > > Cc: beginners-cgi
> > > Subject: Re: 2 Questions
> > >
> > >
> > > I'm still getting the $name requires explicit package name.
> > >
> > > Here is what I have in index.pl
> > >
> > > #!/usr/bin/perl -wT
> > > use strict;
> > > use Data::Dumper;
> > > use CGI qw( :standard );
> > >
> > > print header ( "text/html" );
> > >
> > > my $hash_ref = do ( 'fried.dat' ) || die "error:  unable to open
> > > fried.txt\n";
> > > print Dumper $hash_ref;
> > >
> > > print <<"EndOfHTML";
> > >
> > > $name chicken
> > >
> > > EndOfHTML
> > >
> > >
> > > And here is what I have in fried.dat
> > >
> > > {
> > > name => 'fried'
> > > }
> > >
> > >
> > > I have both chmod'd to 755.  What is wrong with it?
> > >
> > > On Tue, 2 Jul 2002 17:16:00 -0700 (PDT), "Ovid" <[EMAIL PROTECTED]> said:
> > > > --- Kyle Babich <[EMAIL PROTECTED]> wrote:
> > > > > How can I import scalars, arrays, etc. from external perl and text
> > > > > files?
> > > > >
> > > > > This is what I have in index.pl:
> > > > >
> > > > > #!/usr/local/bin/perl -wT
> > > > > use strict;
> > > > > use CGI qw/ :standard /;
> > > > >
> > > > > print header ( 'text/html' );
> > > > >
> > > > > open(TEXT,"<fried.txt") or die ("error:  fried.txt failed\n");
> > > > > while(<TEXT>) {
> > > > > print;
> > > > > }
> > > > > close(TEXT) or die("error:  fried.txt failed\n");
> > > > >
> > > > > print "$name chicken";
> > > > >
> > > > > And this is what I have in fried.txt:
> > > > >
> > > > > my $name = "chicken";
> > > > >
> > > > > So why doesn't it work?
> > > >
> > > > --- Kyle Babich <[EMAIL PROTECTED]> wrote:
> > > > > How can I import scalars, arrays, etc. from external perl and text
> > > > > files?
> > > > >
> > > > > This is what I have in index.pl:
> > > > >
> > > > > #!/usr/local/bin/perl -wT
> > > > > use strict;
> > > > > use CGI qw/ :standard /;
> > > > >
> > > > > print header ( 'text/html' );
> > > > >
> > > > > open(TEXT,"<fried.txt") or die ("error:  fried.txt failed\n");
> > > > > while(<TEXT>) {
> > > > > print;
> > > > > }
> > > > > close(TEXT) or die("error:  fried.txt failed\n");
> > > > >
> > > > > print "$name chicken";
> > > > >
> > > > > And this is what I have in fried.txt:
> > > > >
> > > > > my $name = "chicken";
> > > > >
> > > > > So why doesn't it work?
> > > >
> > > > When declaring variables with 'my', you wind up lexically
> > > scoping them.
> > > >  This is "file" scoped,
> > > > however, so a lexically scoped variable in another file is not
> > > > accessible to you.
> > > >
> > > > One easy (and kind of simplistic) way of getting around
> > > this is to have
> > > > your variables in the
> > > > second file in a hash ref.  Add the following to a file named
> > > > "test.dat":
> > > >
> > > >   {
> > > >     one => 'uno',
> > > >     two => 'dos'
> > > >   }
> > > >
> > > > Then, in the same directory, create and run the following program:
> > > >
> > > >   #!/usr/bin/perl -w
> > > >   use strict;
> > > >   use Data::Dumper;
> > > >
> > > >   my $hash_ref = do ( 'test.dat' ) or die "Cannot open
> > > test.dat: $!";
> > > >   print Dumper $hash_ref;
> > > >
> > > > The above form of 'do' is a special form that "evals" the
> > > contents of
> > > > the file.  The last thing
> > > > returned from the eval is the last results of the last expression
> > > > evaluated, in this case, a hash
> > > > reference.  Be careful with this technique, though.  If someone else
> > > > can alter the contents of
> > > > 'test.dat', you could be eval'ing unsafe code.
> > > >
> > > > Cheers,
> > > > Curtis "Ovid" Poe
> > > >
> > > > =====
> > > > "Ovid" on http://www.perlmonks.org/
> > > > Someone asked me how to count to 10 in Perl:
> > > > push@A,$_ for reverse
> > > q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
> > > > shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print
> > > $_,$/for reverse @A
> > > >
> > > > __________________________________________________
> > > > Do You Yahoo!?
> > > > Sign up for SBC Yahoo! Dial - First Month Free
> > > > http://sbc.yahoo.com
> > > >
> > > >
> > > >
> > > >
> > >
> > > --
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> >
>
> --------------------------------------------------------------------------
> --
> > --------------------
> > The views and opinions expressed in this email message are the sender's
> > own, and do not necessarily represent the views and opinions of Summit
> > Systems Inc.
> >
> >
> >
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to