Professional Web Applications Themes

truncate word - PERL Beginners

Hi I have a file which contains a number of instances of the word "FINAL". I need to truncate all the instances of this word and create an output string of the rest of the words in the same line in the file. Rest all lines not containing the word are to be ignored. For this I have written a code as follows: while(<OUT1>) { if(/FINAL/) { chomp($_); $_ =~ tr/FINAL//d; $sec_seq1 = $sec_seq1 . $_; } } I have also tried something like this: while(<OUT1>) { if(/FINAL/) { chomp($_); $_ =~ s/FINAL//g; $sec_seq1 = $sec_seq1 . $_; } } ...

  1. #1

    Default truncate word

    Hi

    I have a file which contains a number of instances of the word "FINAL".
    I need to truncate all the instances of this word and create an output
    string of the rest of the words in the same line in the file. Rest all
    lines not containing the word are to be ignored. For this I have written
    a code as follows:


    while(<OUT1>) {

    if(/FINAL/) {
    chomp($_);
    $_ =~ tr/FINAL//d;
    $sec_seq1 = $sec_seq1 . $_;
    }

    }

    I have also tried something like this:

    while(<OUT1>) {
    if(/FINAL/) {
    chomp($_);
    $_ =~ s/FINAL//g;
    $sec_seq1 = $sec_seq1 . $_;
    }
    }
    $sec_seq1 =~ tr/ +$//d;

    but it still leaves spaces in all the occurences of the word. Is there
    some problem with this code ?

    Thanks in advance.
    Manas.


    mk76@buffalo.edu Guest

  2. #2

    Default Re: truncate word

    On Sep 20, edu said:
     

    You're using tr/// when you should be using s///.

    while (<OUT1>) {
    if (s/FINAL//) {
    $sec_seq1 .= $_;
    }
    }

    Try that. tr/// is not for regexes, it is for transliterating a set of
    characters to another set of characters.

    # turn a lettered phone number into a regular phone number
    my $phone_number = "1-800-ABC-DEFG";
    $phone_number =~ tr/A-Z/22233344455566677778889999/;

    --
    Jeff "japhy" Pinyan % How can we ever be the sold short or
    RPI Acacia Brother #734 % the cheated, we who for every service
    http://japhy.perlmonk.org/ % have long ago been overpaid?
    http://www.perlmonks.org/ % -- Meister Eckhart

    Jeff Guest

  3. #3

    Default Re: truncate word

    edu wrote: 

    Hello,
     

    If I understand your problem correctly then this should work:

    while ( <OUT1> ) {
    chomp;
    s/\s*FINAL|FINAL\s*//g and $sec_seq1 .= $_;
    }
    }



    John
    --
    use Perl;
    program
    fulfillment
    John Guest

  4. #4

    Default Re: truncate word

    John W. Krahn wrote: [/ref]

    <snip>
     
    >
    > If I understand your problem correctly then this should work:
    >
    > while ( <OUT1> ) {
    > chomp;
    > s/\s*FINAL|FINAL\s*//g and $sec_seq1 .= $_;
    > }
    > }[/ref]

    I fail to see how "FINAL\s*" ever can match if "\s*FINAL" doesn't match.

    It's unclear to me (too?) what exactly the OP wants to do with the
    spaces, but this would replace the word "FINAL" and possible
    surrounding spaces with one space character:

    s/\s*FINAL\s*/ /g

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Guest

  5. #5

    Default calling Perl Script from JSP?


    Anyone know how to call a PERL Script from a JSP and pass parameters to the script?

    I have a JSP that will call PERL but, everytime we try to add a script nothing happens. Any ideas?

    Thanks,

    Drue


    Drue Guest

  6. #6

    Default Two easy questions.



    Truly newbie questions....

    Why do some scripts have a CGI extension while other a .pl and still other a .plx? Does the .cgi extension give it some web characteristics?

    Is there a way to run my script without specifying "perl" before the script? In other words, I want to type c:\myscript.plx instead of c:\perl myscript.plx.

    Thanks,

    Drue


    Drue Guest

  7. #7

    Default Re: truncate word

    Gunnar Hjalmarsson wrote: [/ref]
    >
    > <snip>

    >>
    >> If I understand your problem correctly then this should work:
    >>
    >> while ( <OUT1> ) {
    >> chomp;
    >> s/\s*FINAL|FINAL\s*//g and $sec_seq1 .= $_;
    >> }
    >> }[/ref]
    >
    > I fail to see how "FINAL\s*" ever can match if "\s*FINAL" doesn't match.[/ref]

    Oops, I should have used + instead of * I guess. :-)


    John
    --
    use Perl;
    program
    fulfillment
    John Guest

  8. #8

    Default Re: Two easy questions.


    Your answer actually lies in the system that you are using first. The reason the CGI scripts hold the .cgi extension. Is because that is what your webserver uses to grab your CGI scripts from your CGI directory.

    As for using perl myscript. That is a windows thing. If I remember correctly (Don't qoute me on this, because I don't use perl on windows.) but if you run your script in the directory that you have perl installed in, you don't need the perl part.

    Hopefully I have explained it clearly enough, sorry it is rather late, and I am friggin tired, if when I read this in th morning it sounds ty, I will reword it and re-email it.
    Drue Reeves <net> wrote:


    Truly newbie questions....

    Why do some scripts have a CGI extension while other a .pl and still other a .plx? Does the .cgi extension give it some web characteristics?

    Is there a way to run my script without specifying "perl" before the script? In other words, I want to type c:\myscript.plx instead of c:\perl myscript.plx.

    Thanks,

    Drue



    ---------------------------------
    Do you Yahoo!?
    vote. - Register online to vote today!
    Doug Guest

  9. #9

    Default Re: Two easy questions.

    yes.I think your question is making the 'perl command interpret' default
    to excute the plx file that you made.You can make the configration in
    windos to solve the problem.

    -Sandy




    Drue Reeves wrote:
     

    Le Guest

  10. #10

    Default Re: Two easy questions.

    If you are in 2K or XP you can go to the System Properties screen. In
    there click on the advanced tab then "Environment Variables". Under
    "System Variables" locate PATHEXT. Add ;.pl to the end of the list
    then click OK.

    The system should allow for executing .pl files. As long as you have
    the #!...... info at the top of the file you should be OK.

    Regards,

    --
    --==[ Bob Gordon ]==--
    Bob Guest

Similar Threads

  1. TRUNCATE PAGE
    By GTCGIS in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: February 15th, 03:00 AM
  2. PHP Truncate Text
    By Energize in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 2
    Last Post: August 11th, 02:07 AM
  3. syslog truncate
    By Sinisa in forum SCO
    Replies: 3
    Last Post: August 1st, 01:24 PM
  4. truncate log
    By DRE in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: July 14th, 07:20 PM
  5. Truncate Access
    By Ramandeep Singh in forum Microsoft SQL / MS SQL Server
    Replies: 3
    Last Post: July 1st, 07:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139