Perl Script Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • itzaps
    New Member
    • Sep 2007
    • 5

    Perl Script Problem

    I am writing one perl script which will take value from an external file and then append the value to another file.
    The external file will be in the format like
    $name=value;
    $name1=value1;
    and so on.
    The file may contain several variables like this.
    My problem is how to get these variable values and append those values to another file using a perl script.
    Can anybody help me? I am stuck.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Itzaps. Welcome to TSDN!

    I'm going to go ahead and move this thread to the Perl forum, where our resident Experts will be better able to help you out.

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      Originally posted by itzaps
      I am writing one perl script which will take value from an external file and then append the value to another file.
      The external file will be in the format like
      $name=value;
      $name1=value1;
      and so on.
      The file may contain several variables like this.
      My problem is how to get these variable values and append those values to another file using a perl script.
      Can anybody help me? I am stuck.
      What have you tried so far?

      Comment

      • itzaps
        New Member
        • Sep 2007
        • 5

        #4
        Originally posted by KevinADC
        What have you tried so far?
        I tried printing the 1st character like

        [code=perl]
        $fname = "C:\shared\IQA\ appli.env";
        open(FILE,$fnam e) || die "cannot open File: $!";
        $answer=<FILE>;
        chomp($answer);
        print $answer;
        close(FILE);
        [/code]

        But it is giving output as $name=value where i want the value only
        Last edited by numberwhun; Sep 26 '07, 01:57 PM. Reason: add code tags

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          Originally posted by itzaps
          I tried printing the 1st character like
          name=value where i want the value only
          I am assuming that your env file has that format for each line ( ie: name=value). If that is the case, your script (above) is doing exactly what it is supposed to do. You told it to print each line of input from the file and do nothing else. What you want to do is split each line into its parts and then print the value, like so:

          [code=perl]
          my $fname = "C:\shared\IQA\ appli.env";
          open(FILE, $fname) || die "cannot open File: $!";

          while(<FILE>)
          {
          my $answer="$_";
          chomp($answer);

          my ($name, $value) = split(/\=/, $answer);

          print $value;
          }

          close(FILE);
          [/code]

          Regards,

          Jeff

          Comment

          Working...