Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Characters Between Variables?

    In my perl program I have to write certain details to a file, I am using the code..

    Code:
    open (MYFILE, '>>myfile.txt');
        print MYFILE "Name: $sname $fname\n\n";
    
        close(MYFILE);
    The entered name "Joe Bloggs" will be written as "Bloggs Joe"

    Does any one know how I can edit my code so it writes the name like...

    "BLOGGS_JOE"

    Thanks

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    Thanks that was a good help! I got the uppercase working...new code is

    Code:
    open (MYFILE, '>>myfile.txt');
        print MYFILE "Name: \U$sname $fname\n\n";
    
        close(MYFILE);
    Is there any way to close the \U so that if i add more variables it will only be the name in uppercase, also is there any way i can have a "_" between the 2 names with out having spaces, like I would have put

    Code:
    print MYFILE "Name: \U$sname_$fname\n\n";
    but that doesnt work any ideas?

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts
    There are several ways to accomplish your goal. Here's one:
    Code:
    my $fullname = uc("${sname}_$fname");
    
    print "Name: $fullname\n\n";

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by FishMonger View Post
    There are several ways to accomplish your goal. Here's one:
    Code:
    my $fullname = uc("${sname}_$fname");
    
    print "Name: $fullname\n\n";
    Thanks very much the writing name to file is working perfectly now!

    I also used the approch you provided me to convert email all into 1 value as I had it split up into 3 separtate variables for use with drop boxs etc...

    Code:
    $fullemail = ("${email} @ ${provider} ${domain}");
    When I use this it would generate for example Joe @ aol .com (spaces)

    is there a way to code this so there is no spaces..like "Joe@aol.com" ?

  • #6
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    $fullemail = ("${email} @ ${provider} ${domain}");
    When I use this it would generate for example Joe @ aol .com (spaces)

    is there a way to code this so there is no spaces..like "Joe@aol.com" ?[/QUOTE]

    no1 know how to do this?

  • #7
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Sorry, I've been on a business trip and haven't had the time to respond.

    If you don't want the spaces in the output, then simply remove them from the print statement. You'll also need to escape the @ symbol since that has has special meaning i.e., it's used for arrays.

    Code:
    $fullemail = "${email}\@${provider}${domain}";
    Other options would be to use concatination
    Code:
    $fullemail = ${email} . '@' . $provider . $domain;
    or the join function
    Code:
    $fullmail = join( $email, '@', $provider, $domain );

  • #8
    Regular Coder
    Join Date
    Jun 2003
    Location
    Silicon Forest
    Posts
    155
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Just concatenate the values together with the dot operator:
    Code:
    $fullemail = $email . "@" . $provider . $domain;
    It sounds like you aren't very familiar with perl (or maybe programming languages in general). Perhaps you should read some tutorials to better familiarize yourself with some of these issues.
    Whats the point of a signature?


  •  

    Posting Permissions

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