add a "suffix" to a variable in a array

Discussion in 'Perl Misc' started by Laura, Jul 27, 2004.

  1. Laura

    Laura Guest

    I dont know if I can explain this correctly by here goes.
    I am trying to write a perl program that takes a file let say it looks
    like this...
    xxxx001,00 0 05 21,TELN NOT
    xxxx002,00 0 01 30,TELN NOT
    xxxx008,00 0 04 15,TELN NOT
    xxxx013,00 0 02 30,CUST HAS
    xxxx015,00 0 10 22,CUST HAS

    I want to also insert a few things to this file...
    I want to prompt user to enter in
    print "Enter BLD:"; $bld=<STDIN> ; chomp $bld;
    print "Enter ROOM:"; $ROOM=<STDIN> ; chomp $ROOM;

    Also I want a areacode fixed to the first column so when all is said
    and done, I have part of the script but can not add the areacode to
    it???

    #!/opt/perl/bin/perl
    $acode="204";
    print "Enter BLD:"; $bld=<STDIN> ; chomp $bld;
    print "Enter ROOM:"; $room=<STDIN> ; chomp $room;
    while(<ARGV>) {
    chomp;
    @a=split(",",$_);
    print join(",",$a[0],$bld,$room,$a[1],$a[2],$a[3],"\n") ;

    How do I add 204 at the beginning of the [1]?

    204xxxx001,EAST_BLD,ROOM1,00 0 05 21,TELN NOT
    Laura, Jul 27, 2004
    #1
    1. Advertising

  2. On Mon, 26 Jul 2004 17:52:31 -0700, Laura wrote:

    > I dont know if I can explain this correctly by here goes.
    > I am trying to write a perl program that takes a file let say it looks


    > @a=split(",",$_);
    > print join(",",$a[0],$bld,$room,$a[1],$a[2],$a[3],"\n") ;
    >
    > How do I add 204 at the beginning of the [1]?
    >
    > 204xxxx001,EAST_BLD,ROOM1,00 0 05 21,TELN NOT


    You have 2 choices:

    1) @a=("203",@a);
    2) $a[0] .= "203";

    It works for the whole tri-state area: 202 (NJ), 212, 718, 516 (NYC) and
    203 (CT).

    --
    A city is a large community where people are lonesome together.
    Mladen Gogala, Jul 27, 2004
    #2
    1. Advertising

  3. Laura

    Tony Muler Guest

    Mladen Gogala wrote:

    > You have 2 choices:


    There is more than 2 ways to do it ;-)

    > 1) @a=("203",@a);
    > 2) $a[0] .= "203";


    3) unshift @a, '203';

    However, I tried it with @a having 3 to 20 elements, and
    in either case it doesn't matter in terms of performance.

    T.
    Tony Muler, Jul 27, 2004
    #3
    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. Victor Yuan

    URL without suffix in .Net

    Victor Yuan, Dec 30, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    851
    Dino Chiesa [Microsoft]
    Jan 5, 2005
  2. Green

    what the suffix of the file

    Green, Oct 27, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,167
    Steven Cheng[MSFT]
    Oct 28, 2004
  3. Joseph

    compressed suffix trie

    Joseph, Sep 22, 2004, in forum: Java
    Replies:
    1
    Views:
    512
    =?ISO-8859-1?Q?Daniel_Sj=F6blom?=
    Sep 22, 2004
  4. Andrea Desole

    Parsing double with suffix

    Andrea Desole, Jul 7, 2005, in forum: Java
    Replies:
    2
    Views:
    407
    Andrea Desole
    Jul 7, 2005
  5. Laura
    Replies:
    0
    Views:
    104
    Laura
    Jul 27, 2004
Loading...

Share This Page