Loading ...
Sorry, an error occurred while loading the content.
 

Need help with creating output files

Expand Messages
  • Raquel Mangual
    Hello everyone. I m trying to create a script that will read from a database file and save each record to a separate file. The problem I m having is that I
    Message 1 of 6 , Jul 12 12:22 PM
      Hello everyone. I'm trying to create a script that will read from a
      database file and save each record to a separate file. The problem
      I'm having is that I want the newly created file to be named from
      the "sku" field. When I run the script, I get the "can't open output
      file" message. I've included a copy of the script below. Any
      suggestions would be greatly appreciated. Thanks!

      ****************************************************************

      # Name of the database file to be used in the merge
      $Database = "toys.txt";

      # open the database file but quit if it doesn't exist
      open(INFILE, $Database) or die "The file $Database could not be
      found.\n";

      print "Starting file processing...\n";
      while (<INFILE>)
      {
      $Line = $_; # save the line's contents
      if($Line eq "") {next};
      chomp($Line);
      ($Sku, $Itemname, $Price, $Description, $Category,
      $Imageurl) = split(/\t/, $Line);
      open(OUTFILE, '"$Filename"') or die "Can't open the output
      file.\n";
      print "The sku number is $Sku.\n";
      print "The item name is $Itemname.\n";
      print "The price is \$$Price.\n";
      print "The description is $Description\n";
      print "The category is $Category.\n";
      print "The image URL is $Imageurl\n";
      close(OUTFILE);
      }
      print "File processing complete.\n";
    • Bruce Frizzell
      hi , i do not see where you defined $Filename . perhaps if you add at the beginning : use strict ; $Filename= foo ; ... bonne chance . -- bruce frizzell
      Message 2 of 6 , Jul 12 1:02 PM
        hi ,

        i do not see where you defined $Filename .
        perhaps if you add at the beginning :
        use strict ;
        $Filename="foo" ;

        On 7/12/06, Raquel Mangual <raquel_mangual@...> wrote:
        >
        > Hello everyone. I'm trying to create a script that will read from a
        > database file and save each record to a separate file. The problem
        > I'm having is that I want the newly created file to be named from
        > the "sku" field. When I run the script, I get the "can't open output
        > file" message. I've included a copy of the script below. Any
        > suggestions would be greatly appreciated. Thanks!
        >
        > ****************************************************************
        >
        > # Name of the database file to be used in the merge
        > $Database = "toys.txt";
        >
        > # open the database file but quit if it doesn't exist
        > open(INFILE, $Database) or die "The file $Database could not be
        > found.\n";
        >
        > print "Starting file processing...\n";
        > while (<INFILE>)
        > {
        > $Line = $_; # save the line's contents
        > if($Line eq "") {next};
        > chomp($Line);
        > ($Sku, $Itemname, $Price, $Description, $Category,
        > $Imageurl) = split(/\t/, $Line);
        > open(OUTFILE, '"$Filename"') or die "Can't open the output
        > file.\n";
        > print "The sku number is $Sku.\n";
        > print "The item name is $Itemname.\n";
        > print "The price is \$$Price.\n";
        > print "The description is $Description\n";
        > print "The category is $Category.\n";
        > print "The image URL is $Imageurl\n";
        > close(OUTFILE);
        > }
        > print "File processing complete.\n";
        >
        >
        >


        bonne chance .
        --
        bruce frizzell
        brucefrizzell@...


        [Non-text portions of this message have been removed]
      • Bruce Frizzell
        hi, i also noticed : $Filename = $Sku ; open(OUTFILE, $Filename ) or die Can t open the output file. n ; ^ added the greater than symbol to put something
        Message 3 of 6 , Jul 12 1:49 PM
          hi,

          i also noticed :

          $Filename = $Sku ;
          open(OUTFILE,"> $Filename ") or die "Can't open the output file.\n" ;
          ^
          added the greater than symbol

          to put something in the file :
          print OUTFILE "$Sku \n" ;



          On 7/12/06, Bruce Frizzell <brucefrizzell@...> wrote:
          >
          > hi ,
          >
          > i do not see where you defined $Filename .
          > perhaps if you add at the beginning :
          > use strict ;
          > $Filename="foo" ;
          >
          >
          > On 7/12/06, Raquel Mangual <raquel_mangual@...> wrote:
          > >
          > > Hello everyone. I'm trying to create a script that will read from a
          > > database file and save each record to a separate file. The problem
          > > I'm having is that I want the newly created file to be named from
          > > the "sku" field. When I run the script, I get the "can't open output
          > > file" message. I've included a copy of the script below. Any
          > > suggestions would be greatly appreciated. Thanks!
          > >
          > > ****************************************************************
          > >
          > > # Name of the database file to be used in the merge
          > > $Database = "toys.txt";
          > >
          > > # open the database file but quit if it doesn't exist
          > > open(INFILE, $Database) or die "The file $Database could not be
          > > found.\n";
          > >
          > > print "Starting file processing...\n";
          > > while (<INFILE>)
          > > {
          > > $Line = $_; # save the line's contents
          > > if($Line eq "") {next};
          > > chomp($Line);
          > > ($Sku, $Itemname, $Price, $Description, $Category,
          > > $Imageurl) = split(/\t/, $Line);
          > > open(OUTFILE, '"$Filename"') or die "Can't open the output
          > > file.\n";
          > > print "The sku number is $Sku.\n";
          > > print "The item name is $Itemname.\n";
          > > print "The price is \$$Price.\n";
          > > print "The description is $Description\n";
          > > print "The category is $Category.\n";
          > > print "The image URL is $Imageurl\n";
          > > close(OUTFILE);
          > > }
          > > print "File processing complete.\n";
          > >
          > >
          > >
          >
          >
          > bonne chance .
          > --
          > bruce frizzell
          > brucefrizzell@...
          >



          --
          bruce frizzell
          brucefrizzell@...


          [Non-text portions of this message have been removed]
        • Mr. Shawn H. Corey
          ... use strict; use warnings; ... my $Database = toys.txt ; # All variable need to be declared with # my or our ... # Replace the above three lines with:
          Message 4 of 6 , Jul 12 2:27 PM
            Raquel Mangual wrote:
            > Hello everyone. I'm trying to create a script that will read from a
            > database file and save each record to a separate file. The problem
            > I'm having is that I want the newly created file to be named from
            > the "sku" field. When I run the script, I get the "can't open output
            > file" message. I've included a copy of the script below. Any
            > suggestions would be greatly appreciated. Thanks!
            >
            > ****************************************************************
            >

            use strict;
            use warnings;


            > # Name of the database file to be used in the merge
            > $Database = "toys.txt";
            >

            my $Database = "toys.txt";
            # All variable need to be declared with
            # 'my' or 'our'

            > # open the database file but quit if it doesn't exist
            > open(INFILE, $Database) or die "The file $Database could not be
            > found.\n";
            >
            > print "Starting file processing...\n";
            > while (<INFILE>)
            > {
            > $Line = $_; # save the line's contents
            > if($Line eq "") {next};
            > chomp($Line);

            # Replace the above three lines with:
            chomp;
            next if /^\s*$/;
            my $Line = $_; # save the line's constants

            > ($Sku, $Itemname, $Price, $Description, $Category,
            > $Imageurl) = split(/\t/, $Line);
            > open(OUTFILE, '"$Filename"') or die "Can't open the output
            > file.\n";

            # This is not the form to open a file for output.
            # See `perldoc -f open` for details.

            > print "The sku number is $Sku.\n";
            > print "The item name is $Itemname.\n";
            > print "The price is \$$Price.\n";
            > print "The description is $Description\n";
            > print "The category is $Category.\n";
            > print "The image URL is $Imageurl\n";

            # All of these send the output to STDOUT.
            # To print to your (properly opened) file use the form:
            # print OUTFILE ...


            > close(OUTFILE);
            > }
            > print "File processing complete.\n";
            >
            >
            >
            >


            --
            __END__

            Just my 0.00000002 million dollars worth,
            --- Shawn

            "For the things we have to learn before we can do them, we learn by
            doing them."
            Aristotle

            * Perl tutorials at http://perlmonks.org/?node=Tutorials
            * A searchable perldoc is at http://perldoc.perl.org/
          • tnas
            # All variable need to be declared with # my or our Just when the perl pragma strict is been used.
            Message 5 of 6 , Jul 13 4:00 AM
              # All variable need to be declared with
              # 'my' or 'our'

              Just when the perl pragma 'strict' is been used.



              Mr. Shawn H. Corey escreveu:
              >
              > Raquel Mangual wrote:
              > > Hello everyone. I'm trying to create a script that will read from a
              > > database file and save each record to a separate file. The problem
              > > I'm having is that I want the newly created file to be named from
              > > the "sku" field. When I run the script, I get the "can't open output
              > > file" message. I've included a copy of the script below. Any
              > > suggestions would be greatly appreciated. Thanks!
              > >
              > > ****************************************************************
              > >
              >
              > use strict;
              > use warnings;
              >
              > > # Name of the database file to be used in the merge
              > > $Database = "toys.txt";
              > >
              >
              > my $Database = "toys.txt";
              > # All variable need to be declared with
              > # 'my' or 'our'
              >
              > > # open the database file but quit if it doesn't exist
              > > open(INFILE, $Database) or die "The file $Database could not be
              > > found.\n";
              > >
              > > print "Starting file processing...\n";
              > > while (<INFILE>)
              > > {
              > > $Line = $_; # save the line's contents
              > > if($Line eq "") {next};
              > > chomp($Line);
              >
              > # Replace the above three lines with:
              > chomp;
              > next if /^\s*$/;
              > my $Line = $_; # save the line's constants
              >
              > > ($Sku, $Itemname, $Price, $Description, $Category,
              > > $Imageurl) = split(/\t/, $Line);
              > > open(OUTFILE, '"$Filename"') or die "Can't open the output
              > > file.\n";
              >
              > # This is not the form to open a file for output.
              > # See `perldoc -f open` for details.
              >
              > > print "The sku number is $Sku.\n";
              > > print "The item name is $Itemname.\n";
              > > print "The price is \$$Price.\n";
              > > print "The description is $Description\n";
              > > print "The category is $Category.\n";
              > > print "The image URL is $Imageurl\n";
              >
              > # All of these send the output to STDOUT.
              > # To print to your (properly opened) file use the form:
              > # print OUTFILE ...
              >
              > > close(OUTFILE);
              > > }
              > > print "File processing complete.\n";
              > >
              > >
              > >
              > >
              >
              > --
              > __END__
              >
              > Just my 0.00000002 million dollars worth,
              > --- Shawn
              >
              > "For the things we have to learn before we can do them, we learn by
              > doing them."
              > Aristotle
              >
              > * Perl tutorials at http://perlmonks.org/?node=Tutorials
              > <http://perlmonks.org/?node=Tutorials>
              > * A searchable perldoc is at http://perldoc.perl.org/
              > <http://perldoc.perl.org/>
              >
              >
            • Jabir Ahmed
              open(OUTFILE, $Filename ) or die Can t open the output ... try using open(OUTFILE, $Filename ) or die Can t open the output file. n ; regards jab
              Message 6 of 6 , Jul 13 5:15 AM
                open(OUTFILE, '"$Filename"') or die "Can't open the output
                > > file.\n";
                try using

                open(OUTFILE, '">$Filename"') or die "Can't open the output file.\n";


                regards

                jab
                tnas <nascimentothiago@...> wrote: # All variable need to be declared with
                # 'my' or 'our'

                Just when the perl pragma 'strict' is been used.

                Mr. Shawn H. Corey escreveu:
                >
                > Raquel Mangual wrote:
                > > Hello everyone. I'm trying to create a script that will read from a
                > > database file and save each record to a separate file. The problem
                > > I'm having is that I want the newly created file to be named from
                > > the "sku" field. When I run the script, I get the "can't open output
                > > file" message. I've included a copy of the script below. Any
                > > suggestions would be greatly appreciated. Thanks!
                > >
                > > ****************************************************************
                > >
                >
                > use strict;
                > use warnings;
                >
                > > # Name of the database file to be used in the merge
                > > $Database = "toys.txt";
                > >
                >
                > my $Database = "toys.txt";
                > # All variable need to be declared with
                > # 'my' or 'our'
                >
                > > # open the database file but quit if it doesn't exist
                > > open(INFILE, $Database) or die "The file $Database could not be
                > > found.\n";
                > >
                > > print "Starting file processing...\n";
                > > while (<INFILE>)
                > > {
                > > $Line = $_; # save the line's contents
                > > if($Line eq "") {next};
                > > chomp($Line);
                >
                > # Replace the above three lines with:
                > chomp;
                > next if /^\s*$/;
                > my $Line = $_; # save the line's constants
                >
                > > ($Sku, $Itemname, $Price, $Description, $Category,
                > > $Imageurl) = split(/\t/, $Line);
                > > open(OUTFILE, '"$Filename"') or die "Can't open the output
                > > file.\n";
                >
                > # This is not the form to open a file for output.
                > # See `perldoc -f open` for details.
                >
                > > print "The sku number is $Sku.\n";
                > > print "The item name is $Itemname.\n";
                > > print "The price is \$$Price.\n";
                > > print "The description is $Description\n";
                > > print "The category is $Category.\n";
                > > print "The image URL is $Imageurl\n";
                >
                > # All of these send the output to STDOUT.
                > # To print to your (properly opened) file use the form:
                > # print OUTFILE ...
                >
                > > close(OUTFILE);
                > > }
                > > print "File processing complete.\n";
                > >
                > >
                > >
                > >
                >
                > --
                > __END__
                >
                > Just my 0.00000002 million dollars worth,
                > --- Shawn
                >
                > "For the things we have to learn before we can do them, we learn by
                > doing them."
                > Aristotle
                >
                > * Perl tutorials at http://perlmonks.org/?node=Tutorials
                > <http://perlmonks.org/?node=Tutorials>
                > * A searchable perldoc is at http://perldoc.perl.org/
                > <http://perldoc.perl.org/>
                >
                >





                ---------------------------------
                Sneak preview the all-new Yahoo.com. It's not radically different. Just radically better.

                [Non-text portions of this message have been removed]
              Your message has been successfully submitted and would be delivered to recipients shortly.