perl format statement, how do I begin a line with a hash mark?

Discussion in 'Perl Misc' started by joinerda, May 14, 2010.

  1. joinerda

    joinerda Guest

    I would like to use a perl format statement to autogenerate qsub files
    for a PBS scheduler. The files I need to generate are essentially
    shell scripts with comments beginning with a hash mark to denote them
    as pragma for the scheduler.

    If I create a format statement that looks like

    format QSUBFILE =
    #PBS -N @<<<<<<<<<
    $queue
    ..

    the line beginning with a hash mark is read as a comment by PERL,
    instead of a line that needs to be printed that starts with a hash
    mark.

    How can I using a PERL format statement generate a number of files all
    of which has as their first few lines variations of

    #PBS -N dustfit
    #PBS -q default
    #PBS -l nodes=1:ppn=8
    #PBS -l cput=6000:00:00
     
    joinerda, May 14, 2010
    #1
    1. Advertising

  2. joinerda

    Ralph Malph Guest

    On 5/14/2010 2:35 PM, joinerda wrote:
    > I would like to use a perl format statement to autogenerate qsub files
    > for a PBS scheduler. The files I need to generate are essentially
    > shell scripts with comments beginning with a hash mark to denote them
    > as pragma for the scheduler.
    >
    > If I create a format statement that looks like
    >
    > format QSUBFILE =
    > #PBS -N @<<<<<<<<<
    > $queue
    > .


    The easiest option is to just add a leading space before the #
    format QSUBFILE =
    #PBS -N @<<<<<<<<<
    $queue
     
    Ralph Malph, May 14, 2010
    #2
    1. Advertising

  3. joinerda

    arus Guest

    On 5/14/2010 2:35 PM, joinerda wrote:
    > I would like to use a perl format statement to autogenerate qsub files
    > for a PBS scheduler. The files I need to generate are essentially
    > shell scripts with comments beginning with a hash mark to denote them
    > as pragma for the scheduler.
    >
    > If I create a format statement that looks like
    >
    > format QSUBFILE =
    > #PBS -N @<<<<<<<<<
    > $queue
    > .

    Put the hashmark in a variable
    Eg)
    my $hm="#";
    format QSUBFILE =
    @#PBS -N @<<<<<<<<<
    $hm,$queue
     
    arus, May 14, 2010
    #3
  4. joinerda

    arus Guest

    On 5/14/2010 3:02 PM, arus wrote:
    > On 5/14/2010 2:35 PM, joinerda wrote:
    >> I would like to use a perl format statement to autogenerate qsub files
    >> for a PBS scheduler. The files I need to generate are essentially
    >> shell scripts with comments beginning with a hash mark to denote them
    >> as pragma for the scheduler.
    >>
    >> If I create a format statement that looks like
    >>
    >> format QSUBFILE =
    >> #PBS -N @<<<<<<<<<
    >> $queue
    >> .

    > Put the hashmark in a variable
    > Eg)
    > my $hm="#";
    > format QSUBFILE =
    > @#PBS -N @<<<<<<<<<
    > $hm,$queue
    > .

    I forgot to delete your original #.
    Please correct that to read
    Eg)
    my $hm="#";
    format QSUBFILE =
    @PBS -N @<<<<<<<<<
    $hm,$queue
    ..
     
    arus, May 14, 2010
    #4
  5. joinerda

    joinerda Guest

    I thought about that, but the file has a space in the line that breaks
    the way the file is parsed by the scheduler. I need the first
    character of the line to be a hash. I can do this with print or printf
    statements easily enough, but I am trying to come up with a solution
    where the format statement looks as much as possible like the files my
    end-users (who tend to ask things like "what is backslash n again?")
    are used to dealing with so that this is easier to do in the future.

    On May 14, 2:55 pm, Ralph Malph <> wrote:
    > On 5/14/2010 2:35 PM, joinerda wrote:
    >
    > > I would like to use a perl format statement to autogenerate qsub files
    > > for a PBS scheduler. The files I need to generate are essentially
    > > shell scripts with comments beginning with a hash mark to denote them
    > > as pragma for the scheduler.

    >
    > > If I create a format statement that looks like

    >
    > > format QSUBFILE =
    > > #PBS -N @<<<<<<<<<
    > >          $queue
    > > .

    >
    > The easiest option is to just add a leading space before the #
    > format QSUBFILE =
    >   #PBS -N @<<<<<<<<<
    >           $queue
    >   .
    >
    > will end up printing exactly what you want but the first column will be
    > empty.
     
    joinerda, May 14, 2010
    #5
  6. joinerda <> wrote:
    >I would like to use a perl format statement to autogenerate qsub files


    If I remember correctly there have been previous discussions about
    format() and the general consensus was to use printf() instead, AFAIR
    because printf() is easier to use and has less problems than format().

    jue
     
    Jürgen Exner, May 15, 2010
    #6
    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. Cirene
    Replies:
    5
    Views:
    596
    Cirene
    May 17, 2008
  2. rp
    Replies:
    1
    Views:
    555
    red floyd
    Nov 10, 2011
  3. Srijayanth Sridhar
    Replies:
    19
    Views:
    640
    David A. Black
    Jul 2, 2008
  4. RichardOnRails
    Replies:
    4
    Views:
    188
    RichardOnRails
    Sep 27, 2010
  5. Ting Wang
    Replies:
    3
    Views:
    202
    Paul Lalli
    Dec 13, 2005
Loading...

Share This Page