open(data,' variable problem

Discussion in 'Perl' started by NoViagraHere, Dec 7, 2003.

  1. NoViagraHere

    NoViagraHere Guest

    I am trying to open a text file in the same directory as the script is
    located to retrieve stored info. The text file is simply named:
    216.1.1.2


    This code will NOT work:

    $ip = '216.1.1.2';
    open (data, $ip);
    @mailtext=<data>;
    close data;
    print @mailtext;


    however if I replace $ip as below, It DOES work. Any ideas?

    open (data, '216.1.1.2');
    @mailtext=<data>;
    close data;
    print @mailtext;
    NoViagraHere, Dec 7, 2003
    #1
    1. Advertising

  2. NoViagraHere

    MM Guest

    NoViagraHere wrote:
    > I am trying to open a text file in the same directory as the script is
    > located to retrieve stored info. The text file is simply named:
    > 216.1.1.2
    >
    >
    > This code will NOT work:
    >
    > $ip = '216.1.1.2';
    > open (data, $ip);
    > @mailtext=<data>;
    > close data;
    > print @mailtext;
    >
    >
    > however if I replace $ip as below, It DOES work. Any ideas?
    >
    > open (data, '216.1.1.2');
    > @mailtext=<data>;
    > close data;
    > print @mailtext;
    >
    >


    It works both ways on a Linux system using perl 5.8.1.

    MM
    MM, Dec 7, 2003
    #2
    1. Advertising

  3. NoViagraHere

    Nick Santos Guest

    "MM" <> wrote in message
    news:65MAb.327887$9E1.1609413@attbi_s52...
    > NoViagraHere wrote:
    > > I am trying to open a text file in the same directory as the script is
    > > located to retrieve stored info. The text file is simply named:
    > > 216.1.1.2
    > >
    > >
    > > This code will NOT work:
    > >
    > > $ip = '216.1.1.2';
    > > open (data, $ip);
    > > @mailtext=<data>;
    > > close data;
    > > print @mailtext;
    > >
    > >
    > > however if I replace $ip as below, It DOES work. Any ideas?
    > >
    > > open (data, '216.1.1.2');
    > > @mailtext=<data>;
    > > close data;
    > > print @mailtext;
    > >


    I'd say try making it look like "open (data, '$ip');" or "open (data,
    "$ip");" I doubt it'll work, but it's worth a shot
    Nick Santos, Dec 8, 2003
    #3
  4. NoViagraHere

    Jim Gibson Guest

    In article <3fd2c1a5$0$32845$>, NoViagraHere
    <> wrote:

    > I am trying to open a text file in the same directory as the script is
    > located to retrieve stored info. The text file is simply named:
    > 216.1.1.2
    >
    >
    > This code will NOT work:
    >
    > $ip = '216.1.1.2';
    > open (data, $ip);
    > @mailtext=<data>;
    > close data;
    > print @mailtext;
    >
    >
    > however if I replace $ip as below, It DOES work. Any ideas?
    >
    > open (data, '216.1.1.2');
    > @mailtext=<data>;
    > close data;
    > print @mailtext;
    >
    >


    You don't say why it is not working. You should be checking if the open
    succeeded:

    open( data, $ip ) or die("Can't open $ip: $!");

    FYI: this newsgroup is defunct. Use comp.lang.perl.misc in the future
    for better response.
    Jim Gibson, Dec 9, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pratham
    Replies:
    3
    Views:
    685
    sloan
    Aug 31, 2006
  2. mfglinux
    Replies:
    11
    Views:
    687
    Roberto Bonvallet
    Sep 12, 2007
  3. Steve Cosh
    Replies:
    1
    Views:
    160
    joewiii
    Nov 18, 2005
  4. Matt
    Replies:
    1
    Views:
    453
    Michael Winter
    Aug 22, 2004
  5. David Filmer
    Replies:
    19
    Views:
    227
    Kevin Collins
    May 21, 2004
Loading...

Share This Page