Windows Vista Forums

Perl split function equivalent
  1. #1


    Frank Guest

    Perl split function equivalent

    It is definate that PowerShell is very powerful with hooks to WMI and so
    forth but it appears to be lacking of some string manipulation functions. I
    am a newbie to PowerShell but I cannot find anything close to the Perl split.
    I found a regex split but that isn't what I really needed. What I need is:

    my ($f1,$f2) = split (/,/, $record);
    my $total = $f2 + $count;

    to split the fields delimeted by a comma, then I would like to deal only
    with field two. Is this possible?

    Thanks in advance





      My System SpecsSystem Spec

  2. #2


    William Stacey [C# MVP] Guest

    Re: Perl split function equivalent

    PS C:\TEMP> $line = "one,3"
    PS C:\TEMP> $total = $line.split(",")[1] + $count

    --
    William Stacey [C# MVP]
    PCR concurrency library: www.codeplex.com/pcr
    PSH Scripts Project www.codeplex.com/psobject


    "Frank" <Frank@discussions.microsoft.com> wrote in message
    news:F807C9A2-F28F-479C-88AA-C50AF166010D@microsoft.com...
    | It is definate that PowerShell is very powerful with hooks to WMI and so
    | forth but it appears to be lacking of some string manipulation functions.
    I
    | am a newbie to PowerShell but I cannot find anything close to the Perl
    split.
    | I found a regex split but that isn't what I really needed. What I need
    is:
    |
    | my ($f1,$f2) = split (/,/, $record);
    | my $total = $f2 + $count;
    |
    | to split the fields delimeted by a comma, then I would like to deal only
    | with field two. Is this possible?
    |
    | Thanks in advance
    |
    |



      My System SpecsSystem Spec

  3. #3


    mikes.net Guest

    Re: Perl split function equivalent

    Hi,

    PS > "1,2,3".split(',')
    1
    2
    3
    PS > $a,$b = "1,2,3".split(',')
    PS > $a
    1
    PS > $b
    2
    3
    PS > $a + [Math]::Pi # Note $a was parsed as a string.
    13.14159265358979
    PS > [int]$a + [Math]::Pi
    4.14159265358979
    PS >

    You will also want to read up on the -match and -replace
    operators, which are sometimes convenient for pattern matching.

    The most important cmdlet to know and use often is Get-Member. As
    a Perl user the trickiest cmdlets for you will be Get-Content, Set-
    Content, Get-ChildItem.

    Mike


    On Feb 14, 6:20 pm, Frank <F...@discussions.microsoft.com> wrote:
    > It is definate that PowerShell is very powerful with hooks to WMI and so
    > forth but it appears to be lacking of some string manipulation functions. I
    > am a newbie to PowerShell but I cannot find anything close to the Perl split.
    > I found a regex split but that isn't what I really needed. What I need is:
    >
    > my ($f1,$f2) = split (/,/, $record);
    > my $total = $f2 + $count;
    >
    > to split the fields delimeted by a comma, then I would like to deal only
    > with field two. Is this possible?
    >
    > Thanks in advance




      My System SpecsSystem Spec

  4. #4


    William Stacey [C# MVP] Guest

    Re: Perl split function equivalent


    | PS > $a,$b = "1,2,3".split(',')

    I love this little ditty. We need to keep in mind it does involve another
    array alloc (and array copy) each time we do it. But I do like it soo.
    --wjs



      My System SpecsSystem Spec

Perl split function equivalent problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Split function... popular topic today! Dan VB Script 7 23 Mar 2010
VBscript Array Split Function turtle VB Script 9 03 Apr 2009
Problem using split function Meat VB Script 2 23 Jul 2008
Split function IT Staff PowerShell 6 24 Oct 2007
Is there an equivalent of the DOS pause function Fil PowerShell 3 22 Nov 2006