header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
eliminating temporary variable
Last Post 30 Apr 2008 05:02 AM by halr9000. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
John D. CookUser is Offline
New Member
New Member
Posts:7
Avatar

--
30 Apr 2008 03:26 AM

    I've written a one-liner that munges the contents of the clipboard using the PSCX cmdlets get-clipboard and out-clipboard. I needed to replace each block of whitespace with a comma. How could I eliminate the temporary variable $a?

    $a = get-clipboard; $a -replace '\s+', ',' | out-clipboard 

    Thanks.

    halr9000User is Offline
    PowerShell MVP, Site Admin
    Advanced Member
    Advanced Member
    Posts:565
    Avatar

    --
    30 Apr 2008 05:02 AM
    No problem, just add parentheses. (get-clipboard) -replace "foo" | out-clipboard

    Otherwise, the parser will try to pass -replace to get-clipboard as a parameter.
    Community Director, PowerShellCommunity.org
    Co-host, PowerScripting Podcast
    Author, TechProsaic
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer