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

Re: Help with variable

Expand Messages
  • Damien Carbery
    ... Since you haven t provided any code it is impossible to help you. Instead of using the external mkdir command (you show backticks above) use the internal
    Message 1 of 9 , Oct 4, 2005
    • 0 Attachment
      --- In perl-beginner@yahoogroups.com, "sherry_vlsi"
      <sarathdhulipalla@y...> wrote:
      > Hi,
      > i am new to perl. I got a problem. I am writing a script to create a
      > directory whose name will be generated in the script. for example one
      > of the directory name I need to create will be 9.1.3C I am getting
      > this value in a variable ($dirname) and I am using
      > print `mkdir C:/perl/$dirname` command to create it. Since the value
      > includes a Charecter perl is giving me syntax error. If the value is
      > just 9.1.3 the print line is working fine. But with that charecter at
      > the end I am getting problems. Can anyone solve my problem?
      >
      > Thanks

      Since you haven't provided any code it is impossible to help you.
      Instead of using the external 'mkdir' command (you show backticks
      above) use the internal mkdir function - it's quicker.

      Change:
      `mkdir C:/perl/$dirname`;
      to:
      mkdir "C:/perl/$dirname";
    • Ezra Taylor
      Hello Sherry: Try to escape the .3c like .3c Ezra
      Message 2 of 9 , Oct 4, 2005
      • 0 Attachment
        Hello Sherry:
        Try to escape the .3c like \.3c

        Ezra

        On 10/3/05, sherry_vlsi <sarathdhulipalla@...> wrote:
        > Hi,
        > i am new to perl. I got a problem. I am writing a script to create a
        > directory whose name will be generated in the script. for example one
        > of the directory name I need to create will be 9.1.3C I am getting
        > this value in a variable ($dirname) and I am using
        > print `mkdir C:/perl/$dirname` command to create it. Since the value
        > includes a Charecter perl is giving me syntax error. If the value is
        > just 9.1.3 the print line is working fine. But with that charecter at
        > the end I am getting problems. Can anyone solve my problem?
        >
        > Thanks
        >
        >
        >
        >
        >
        > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
        >
        >
      • Shawn Corey
        ... The line: print `mkdir C:/perl/$dirname` mixes two nomenclatures, MS DOS and UNIX. C: is MS DOS and /perl/ is UNIX. Try: mkdir C:/perl/$dirname ; You
        Message 3 of 9 , Oct 4, 2005
        • 0 Attachment
          sherry_vlsi wrote:
          > Hi,
          > i am new to perl. I got a problem. I am writing a script to create a
          > directory whose name will be generated in the script. for example one
          > of the directory name I need to create will be 9.1.3C I am getting
          > this value in a variable ($dirname) and I am using
          > print `mkdir C:/perl/$dirname` command to create it. Since the value
          > includes a Charecter perl is giving me syntax error. If the value is
          > just 9.1.3 the print line is working fine. But with that charecter at
          > the end I am getting problems. Can anyone solve my problem?

          The line: print `mkdir C:/perl/$dirname` mixes two nomenclatures, MS DOS
          and UNIX. 'C:' is MS DOS and '/perl/' is UNIX.

          Try: mkdir "C:/perl/$dirname";
          You can mix them if you remain inside Perl. See perldoc -f mkdir.


          --- Shawn
        • sarath
          Hi, thanks for the reply. But the problem is the directory name is computed in the script. It changes every time. I am extracting the directory name from a log
          Message 4 of 9 , Oct 4, 2005
          • 0 Attachment
            Hi,

            thanks for the reply. But the problem is the directory name is computed in the script. It changes every time. I am extracting the directory name from a log file into $dirname. How can I exscape something that is stored in a variable like $dirname?

            Thanks
            Sarath.


            Ezra Taylor <ezra.taylor@...> wrote:
            Hello Sherry:
            Try to escape the .3c like \.3c

            Ezra

            On 10/3/05, sherry_vlsi <sarathdhulipalla@...> wrote:
            > Hi,
            > i am new to perl. I got a problem. I am writing a script to create a
            > directory whose name will be generated in the script. for example one
            > of the directory name I need to create will be 9.1.3C I am getting
            > this value in a variable ($dirname) and I am using
            > print `mkdir C:/perl/$dirname` command to create it. Since the value
            > includes a Charecter perl is giving me syntax error. If the value is
            > just 9.1.3 the print line is working fine. But with that charecter at
            > the end I am getting problems. Can anyone solve my problem?
            >
            > Thanks
            >
            >
            >
            >
            >
            > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
            > Yahoo! Groups Links
            >
            >
            >
            >
            >
            >
            >


            Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html



            ---------------------------------
            YAHOO! GROUPS LINKS


            Visit your group "perl-beginner" on the web.

            To unsubscribe from this group, send an email to:
            perl-beginner-unsubscribe@yahoogroups.com

            Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


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






            ****************************************************************************
            BE ALONE TO BE HAPPY. BE HAPPY TO BE ALONE
            ****************************************************************************






            ---------------------------------
            Yahoo! India Matrimony: Find your partner now.

            [Non-text portions of this message have been removed]
          • Shawn Corey
            ... Are you running under UNIX or MS DOS? Under UNIX the only character that needs be escaped is / . MS DOS on the other hand has many special characters,
            Message 5 of 9 , Oct 4, 2005
            • 0 Attachment
              sarath wrote:
              > Hi,
              >
              > thanks for the reply. But the problem is the directory name is computed
              > in the script. It changes every time. I am extracting the directory name
              > from a log file into $dirname. How can I exscape something that is
              > stored in a variable like $dirname?

              Are you running under UNIX or MS DOS? Under UNIX the only character that
              needs be escaped is '/'. MS DOS on the other hand has many special
              characters, most of which cannot be used in a file name. It is better to
              just replace them:

              $dirname =~ s/\W+/_/g;


              --- Shawn
            • Damien Carbery
              ... computed ... directory name ... that ... better to ... Shawn - that substitution is a bit drastic. It will convert spaces to underscores and spaces are
              Message 6 of 9 , Oct 5, 2005
              • 0 Attachment
                --- In perl-beginner@yahoogroups.com, Shawn Corey <shawn.corey@s...>
                wrote:
                > sarath wrote:
                > > Hi,
                > >
                > > thanks for the reply. But the problem is the directory name is
                computed
                > > in the script. It changes every time. I am extracting the
                directory name
                > > from a log file into $dirname. How can I exscape something that is
                > > stored in a variable like $dirname?
                >
                > Are you running under UNIX or MS DOS? Under UNIX the only character
                that
                > needs be escaped is '/'. MS DOS on the other hand has many special
                > characters, most of which cannot be used in a file name. It is
                better to
                > just replace them:
                >
                > $dirname =~ s/\W+/_/g;
                >
                >
                > --- Shawn

                Shawn - that substitution is a bit drastic. It will convert spaces to
                underscores and spaces are valid file name characters in Windows (and
                Unix).

                > and I am using print `mkdir C:/perl/$dirname` command to create it.
                Have you tried my suggestion?
                mkdir( "C:/perl/$dirname" );

                Please also provide us with some code from your script. Even better,
                write a small script that has the same problem, just set $dirname to a
                value that causes the problem.
                Something like:

                #!/usr/bin/perl -w
                use strict;
                my $dirname = '9.1.3C'; # Change this as nessary.
                # So you and we can see the value.
                print "OS: $^O, \$dirname: $dirname\n";
                mkdir "C:/Perl/$dirname";
                # 1 (one) is good. If it fails an error message will be printed.
                print "mkdir result: $? $!\n";

                If *you* run this and report back on the results to us we might be
                able to help you. Until then there'll be a lot of guessing.
              • Ray Brannam
                ... Actually that is not quite correct, there are many characters that need escaping e.g. , , , ,| to name a few. It would be better if you explain
                Message 7 of 9 , Oct 5, 2005
                • 0 Attachment
                  Damien Carbery wrote:

                  >--- In perl-beginner@yahoogroups.com, Shawn Corey <shawn.corey@s...>
                  >wrote:
                  >
                  >
                  >>sarath wrote:
                  >>
                  >>
                  >>>Hi,
                  >>>
                  >>>thanks for the reply. But the problem is the directory name is
                  >>>
                  >>>
                  >computed
                  >
                  >
                  >>>in the script. It changes every time. I am extracting the
                  >>>
                  >>>
                  >directory name
                  >
                  >
                  >>>from a log file into $dirname. How can I exscape something that is
                  >>>stored in a variable like $dirname?
                  >>>
                  >>>
                  >>Are you running under UNIX or MS DOS? Under UNIX the only character
                  >>
                  >>
                  >that
                  >
                  >
                  >>needs be escaped is '/'. MS DOS on the other hand has many special
                  >>characters, most of which cannot be used in a file name. It is
                  >>
                  >>
                  >better to
                  >
                  >
                  >>just replace them:
                  >>
                  >> $dirname =~ s/\W+/_/g;
                  >>
                  >>
                  >> --- Shawn
                  >>
                  >>
                  >
                  >Shawn - that substitution is a bit drastic. It will convert spaces to
                  >underscores and spaces are valid file name characters in Windows (and
                  >Unix).
                  >
                  >
                  >
                  >>and I am using print `mkdir C:/perl/$dirname` command to create it.
                  >>
                  >>
                  >Have you tried my suggestion?
                  >mkdir( "C:/perl/$dirname" );
                  >
                  >Please also provide us with some code from your script. Even better,
                  >write a small script that has the same problem, just set $dirname to a
                  >value that causes the problem.
                  >Something like:
                  >
                  >#!/usr/bin/perl -w
                  >use strict;
                  >my $dirname = '9.1.3C'; # Change this as nessary.
                  ># So you and we can see the value.
                  >print "OS: $^O, \$dirname: $dirname\n";
                  >mkdir "C:/Perl/$dirname";
                  ># 1 (one) is good. If it fails an error message will be printed.
                  >print "mkdir result: $? $!\n";
                  >
                  >If *you* run this and report back on the results to us we might be
                  >able to help you. Until then there'll be a lot of guessing.
                  >
                  >
                  >

                  Actually that is not quite correct, there are many characters that need escaping e.g. <spaces>, ',",\,| to name a few.

                  It would be better if you explain what you are trying to do and provide some sample code. It is far easier if we understand what you are trying to accomplish.

                  --Ray




                  [Non-text portions of this message have been removed]
                • Shawn Corey
                  ... That depends on whether you are doing in Perl or in a shell. In Perl, only / and (I missed this one) need be escaped by placing a backslash in front
                  Message 8 of 9 , Oct 5, 2005
                  • 0 Attachment
                    Ray Brannam wrote:
                    > Actually that is not quite correct, there are many characters that need
                    > escaping e.g. <spaces>, ',",\,| to name a few.

                    That depends on whether you are doing in Perl or in a shell. In Perl,
                    only '/' and '\' (I missed this one) need be escaped by placing a
                    backslash in front of it. This is because Perl uses them as directory
                    separators. '/' is from UNIX and '\' is from MS DOS; Perl uses both
                    interchangeably.

                    In a shell, that depends on the shell. I would not recommend using it
                    from a shell since the variable is tainted. I could call it something
                    like 'foo; rm -rf / 2>/dev/null' with very unpleasant results. See
                    perldoc -q taint


                    --- Shawn
                  Your message has been successfully submitted and would be delivered to recipients shortly.