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 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    86
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Help Please With Perl Regex

    I can do this with php but I'm not to good with perl. I have a script that graps a user name but some usernames have a slash in them. What I need to do is write an if statement that looks for a username with a slash and then divides the two names so that i have two variables.

    ie.

    $user = art/mysite

    I need this instead

    $user1 = art;

    $user2 = mysite;


    Thanks
    Last edited by Jinxy; 05-25-2011 at 04:25 PM.

  • #2
    New Coder
    Join Date
    Oct 2006
    Posts
    68
    Thanks
    0
    Thanked 28 Times in 28 Posts
    Code:
    my $user = 'art/mysite';
    
    if ($user =~ m{/}) {
        print "it has a slash\n";
    }
    or a good ole split would work.

    Code:
    my @names =  split '/', $user;

  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    86
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Thank you! That's exactly what I needed.


  •  

    Posting Permissions

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