I need help with "lines"

Hi All,

What am I doing wrong here?

ps ax | grep [f]irefox | perl6 -ne 'my @x = $_.words[0].lines.reverse; 
print @x[0] ~ "\n";'
7380
7581
7698
13023
13767
13908


Two problems:

1) "lines" is putting everything into @x[0]

2) "reverse" is ignoring me as there is no @x[1]. etc.

The result I want is 13908

Many thanks,
-T
0
perl6
3/15/2019 5:05:17 AM
perl.perl6.users 1152 articles. 0 followers. Follow

16 Replies
15 Views

Similar Articles

[PageSpeed] 10


On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:
> Hi All,
> 
> What am I doing wrong here?
> 
> ps ax | grep [f]irefox | perl6 -ne 'my @x = $_.words[0].lines.reverse; 
> print @x[0] ~ "\n";'
> 7380
> 7581
> 7698
> 13023
> 13767
> 13908
> 
> 
> Two problems:
> 
> 1) "lines" is putting everything into @x[0]
> 
> 2) "reverse" is ignoring me as there is no @x[1]. etc.
> 
> The result I want is 13908
> 
> Many thanks,
> -T

And why do I have a broken pipe here?

$ ps ax | grep [f]irefox | perl6 -ne 'say $_.lines.sort.reverse.words[0];'
7380
7581
7698
13023
13767
22369

$ ps ax | grep [f]irefox | perl6 -ne 'say 
$_.lines.sort.reverse.words[0];' | sort -r

Failed to write bytes to filehandle: Broken pipe
   in block <unit> at -e line 1
0
perl6
3/15/2019 5:34:17 AM
--000000000000a4b0b905841ba996
Content-Type: text/plain; charset="UTF-8"

6am here and I'm not at a computer but I think your problem is trying to
use both -n which runs your code on each line of STDIN and lines.

Try one or the other see what happens.

Once I'm ambulant and at a computer I'll poke at it myself.

On Fri, 15 Mar 2019, 05:34 Todd Chester via perl6-users, <
perl6-users@perl.org> wrote:

>
>
> On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:
> > Hi All,
> >
> > What am I doing wrong here?
> >
> > ps ax | grep [f]irefox | perl6 -ne 'my @x = $_.words[0].lines.reverse;
> > print @x[0] ~ "\n";'
> > 7380
> > 7581
> > 7698
> > 13023
> > 13767
> > 13908
> >
> >
> > Two problems:
> >
> > 1) "lines" is putting everything into @x[0]
> >
> > 2) "reverse" is ignoring me as there is no @x[1]. etc.
> >
> > The result I want is 13908
> >
> > Many thanks,
> > -T
>
> And why do I have a broken pipe here?
>
> $ ps ax | grep [f]irefox | perl6 -ne 'say $_.lines.sort.reverse.words[0];'
> 7380
> 7581
> 7698
> 13023
> 13767
> 22369
>
> $ ps ax | grep [f]irefox | perl6 -ne 'say
> $_.lines.sort.reverse.words[0];' | sort -r
>
> Failed to write bytes to filehandle: Broken pipe
>    in block <unit> at -e line 1
>

--000000000000a4b0b905841ba996
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">6am here and I&#39;m not at a computer but I think your p=
roblem is trying to use both -n which runs your code on each line of STDIN =
and lines.<div dir=3D"auto"><br></div><div dir=3D"auto">Try one or the othe=
r see what happens.</div><div dir=3D"auto"><br></div><div dir=3D"auto">Once=
 I&#39;m ambulant and at a computer I&#39;ll poke at it myself.</div></div>=
<br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Fri=
, 15 Mar 2019, 05:34 Todd Chester via perl6-users, &lt;<a href=3D"mailto:pe=
rl6-users@perl.org">perl6-users@perl.org</a>&gt; wrote:<br></div><blockquot=
e class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc sol=
id;padding-left:1ex"><br>
<br>
On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:<br>
&gt; Hi All,<br>
&gt; <br>
&gt; What am I doing wrong here?<br>
&gt; <br>
&gt; ps ax | grep [f]irefox | perl6 -ne &#39;my @x =3D $_.words[0].lines.re=
verse; <br>
&gt; print @x[0] ~ &quot;\n&quot;;&#39;<br>
&gt; 7380<br>
&gt; 7581<br>
&gt; 7698<br>
&gt; 13023<br>
&gt; 13767<br>
&gt; 13908<br>
&gt; <br>
&gt; <br>
&gt; Two problems:<br>
&gt; <br>
&gt; 1) &quot;lines&quot; is putting everything into @x[0]<br>
&gt; <br>
&gt; 2) &quot;reverse&quot; is ignoring me as there is no @x[1]. etc.<br>
&gt; <br>
&gt; The result I want is 13908<br>
&gt; <br>
&gt; Many thanks,<br>
&gt; -T<br>
<br>
And why do I have a broken pipe here?<br>
<br>
$ ps ax | grep [f]irefox | perl6 -ne &#39;say $_.lines.sort.reverse.words[0=
];&#39;<br>
7380<br>
7581<br>
7698<br>
13023<br>
13767<br>
22369<br>
<br>
$ ps ax | grep [f]irefox | perl6 -ne &#39;say <br>
$_.lines.sort.reverse.words[0];&#39; | sort -r<br>
<br>
Failed to write bytes to filehandle: Broken pipe<br>
=C2=A0 =C2=A0in block &lt;unit&gt; at -e line 1<br>
</blockquote></div>

--000000000000a4b0b905841ba996--
0
simon
3/15/2019 5:53:38 AM
>> On Fri, 15 Mar 2019, 05:34 Todd Chester via perl6-users, 
>> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>> 
>> 
>> 
>>     On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:
>>      > Hi All,
>>      >
>>      > What am I doing wrong here?
>>      >
>>      > ps ax | grep [f]irefox | perl6 -ne 'my @x =
>>     $_.words[0].lines.reverse;
>>      > print @x[0] ~ "\n";'
>>      > 7380
>>      > 7581
>>      > 7698
>>      > 13023
>>      > 13767
>>      > 13908
>>      >
>>      >
>>      > Two problems:
>>      >
>>      > 1) "lines" is putting everything into @x[0]
>>      >
>>      > 2) "reverse" is ignoring me as there is no @x[1]. etc.
>>      >
>>      > The result I want is 13908
>>      >
>>      > Many thanks,
>>      > -T
>> 
>>     And why do I have a broken pipe here?
>> 
>>     $ ps ax | grep [f]irefox | perl6 -ne 'say
>>     $_.lines.sort.reverse.words[0];'
>>     7380
>>     7581
>>     7698
>>     13023
>>     13767
>>     22369
>> 
>>     $ ps ax | grep [f]irefox | perl6 -ne 'say
>>     $_.lines.sort.reverse.words[0];' | sort -r
>> 
>>     Failed to write bytes to filehandle: Broken pipe
>>         in block <unit> at -e line 1
>> 



On 3/14/19 10:53 PM, Simon Proctor wrote:
> 6am here and I'm not at a computer but I think your problem is trying to 
> use both -n which runs your code on each line of STDIN and lines.
> 
> Try one or the other see what happens.
> 
> Once I'm ambulant and at a computer I'll poke at it myself.


Thank you anyway.


$ ps ax | grep [f]irefox | perl6 -n 'my @x = $_.words[0].lines.reverse; 
print @x[0] ~ "\n";'
Could not open my @x = $_.words[0].lines.reverse; print @x[0] ~ "\n";. 
Failed to stat file: no such file or directory

$ ps ax | grep [f]irefox | perl6 -e 'my @x = $_.words[0].lines.reverse; 
print @x[0] ~ "\n";'
No such method 'words' for invocant of type 'Any'
   in block <unit> at -e line 1

> 
0
perl6
3/15/2019 6:14:17 AM

On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:
> Hi All,
> 
> What am I doing wrong here?
> 
> ps ax | grep [f]irefox | perl6 -ne 'my @x = $_.words[0].lines.reverse; 
> print @x[0] ~ "\n";'
> 7380
> 7581
> 7698
> 13023
> 13767
> 13908
> 
> 
> Two problems:
> 
> 1) "lines" is putting everything into @x[0]
> 
> 2) "reverse" is ignoring me as there is no @x[1]. etc.
> 
> The result I want is 13908
> 
> Many thanks,
> -T


This is what I am trying to duplicate:

$ ps ax | grep [f]irefox | awk '{print $1}' | /usr/bin/sort -r | 
/usr/bin/sed -n '1,1p'

7814
0
perl6
3/15/2019 9:27:11 AM
--000000000000d3c7d305841ec1d8
Content-Type: text/plain; charset="UTF-8"

Ok so in this kind of situation I tend to break it down into smaller stages
so :

ps ax | grep [f]irefox
 4277 tty2     Sl+    1:08 /usr/lib/firefox/firefox
 4780 tty2     Sl+    2:44 /usr/lib/firefox/firefox -contentproc -childID 1
-isForBrowser -prefsLen 1 -prefMapSize 177920 -schedulerPrefs 0001,2
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni
/usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true
tab
 5088 tty2     Sl+    0:27 /usr/lib/firefox/firefox -contentproc -childID 2
-isForBrowser -prefsLen 82 -prefMapSize 177920 -schedulerPrefs 0001,2
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni
/usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true
tab
 5094 tty2     Sl+    1:15 /usr/lib/firefox/firefox -contentproc -childID 3
-isForBrowser -prefsLen 82 -prefMapSize 177920 -schedulerPrefs 0001,2
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni
/usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true
tab
 5106 tty2     Sl+    1:02 /usr/lib/firefox/firefox -contentproc -childID 4
-isForBrowser -prefsLen 82 -prefMapSize 177920 -schedulerPrefs 0001,2
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni
/usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true
tab
 5188 tty2     Sl+    0:16 /usr/lib/firefox/firefox -contentproc -childID 5
-isForBrowser -prefsLen 176 -prefMapSize 177920 -schedulerPrefs 0001,2
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni
/usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true
tab
 5734 tty2     Sl+    0:07 /usr/lib/firefox/firefox -contentproc -childID 6
-isForBrowser -prefsLen 6102 -prefMapSize 177920 -schedulerPrefs 0001,2
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni
/usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true
tab

Then :

ps ax | grep [f]irefox | perl -ne '@x = .words; @x.say'

[4277 tty2 Sl+ 1:10 /usr/lib/firefox/firefox]
[4780 tty2 Sl+ 2:50 /usr/lib/firefox/firefox -contentproc -childID 1
-isForBrowser -prefsLen 1 -prefMapSize 177920 -schedulerPrefs 0001,2
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni
/usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true
tab]
[5088 tty2 Sl+ 0:27 /usr/lib/firefox/firefox -contentproc -childID 2
-isForBrowser -prefsLen 82 -prefMapSize 177920 -schedulerPrefs 0001,2
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni
/usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true
tab]
[5094 tty2 Sl+ 1:18 /usr/lib/firefox/firefox -contentproc -childID 3
-isForBrowser -prefsLen 82 -prefMapSize 177920 -schedulerPrefs 0001,2
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni
/usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true
tab]
[5106 tty2 Sl+ 1:02 /usr/lib/firefox/firefox -contentproc -childID 4
-isForBrowser -prefsLen 82 -prefMapSize 177920 -schedulerPrefs 0001,2
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni
/usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true
tab]
[5188 tty2 Sl+ 0:16 /usr/lib/firefox/firefox -contentproc -childID 5
-isForBrowser -prefsLen 176 -prefMapSize 177920 -schedulerPrefs 0001,2
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni
/usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true
tab]
[5734 tty2 Sl+ 0:07 /usr/lib/firefox/firefox -contentproc -childID 6
-isForBrowser -prefsLen 6102 -prefMapSize 177920 -schedulerPrefs 0001,2
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni
/usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true
tab]

All looking good so far. what is it you're wanting from this data?


On Fri, 15 Mar 2019 at 06:14, Todd Chester via perl6-users <
perl6-users@perl.org> wrote:

> >> On Fri, 15 Mar 2019, 05:34 Todd Chester via perl6-users,
> >> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
> >>
> >>
> >>
> >>     On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:
> >>      > Hi All,
> >>      >
> >>      > What am I doing wrong here?
> >>      >
> >>      > ps ax | grep [f]irefox | perl6 -ne 'my @x =
> >>     $_.words[0].lines.reverse;
> >>      > print @x[0] ~ "\n";'
> >>      > 7380
> >>      > 7581
> >>      > 7698
> >>      > 13023
> >>      > 13767
> >>      > 13908
> >>      >
> >>      >
> >>      > Two problems:
> >>      >
> >>      > 1) "lines" is putting everything into @x[0]
> >>      >
> >>      > 2) "reverse" is ignoring me as there is no @x[1]. etc.
> >>      >
> >>      > The result I want is 13908
> >>      >
> >>      > Many thanks,
> >>      > -T
> >>
> >>     And why do I have a broken pipe here?
> >>
> >>     $ ps ax | grep [f]irefox | perl6 -ne 'say
> >>     $_.lines.sort.reverse.words[0];'
> >>     7380
> >>     7581
> >>     7698
> >>     13023
> >>     13767
> >>     22369
> >>
> >>     $ ps ax | grep [f]irefox | perl6 -ne 'say
> >>     $_.lines.sort.reverse.words[0];' | sort -r
> >>
> >>     Failed to write bytes to filehandle: Broken pipe
> >>         in block <unit> at -e line 1
> >>
>
>
>
> On 3/14/19 10:53 PM, Simon Proctor wrote:
> > 6am here and I'm not at a computer but I think your problem is trying to
> > use both -n which runs your code on each line of STDIN and lines.
> >
> > Try one or the other see what happens.
> >
> > Once I'm ambulant and at a computer I'll poke at it myself.
>
>
> Thank you anyway.
>
>
> $ ps ax | grep [f]irefox | perl6 -n 'my @x = $_.words[0].lines.reverse;
> print @x[0] ~ "\n";'
> Could not open my @x = $_.words[0].lines.reverse; print @x[0] ~ "\n";.
> Failed to stat file: no such file or directory
>
> $ ps ax | grep [f]irefox | perl6 -e 'my @x = $_.words[0].lines.reverse;
> print @x[0] ~ "\n";'
> No such method 'words' for invocant of type 'Any'
>    in block <unit> at -e line 1
>
> >
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/

--000000000000d3c7d305841ec1d8
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div>Ok so in this kind =
of situation I tend to break it down into smaller stages so :<br></div><div=
><br></div><div>ps ax | grep [f]irefox<br>=C2=A04277 tty2=C2=A0=C2=A0=C2=A0=
=C2=A0 Sl+=C2=A0=C2=A0=C2=A0 1:08 /usr/lib/firefox/firefox<br>=C2=A04780 tt=
y2=C2=A0=C2=A0=C2=A0=C2=A0 Sl+=C2=A0=C2=A0=C2=A0 2:44 /usr/lib/firefox/fire=
fox -contentproc -childID 1 -isForBrowser -prefsLen 1 -prefMapSize 177920 -=
schedulerPrefs 0001,2 -parentBuildID 20190215001155 -greomni /usr/lib/firef=
ox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firef=
ox/browser 4277 true tab<br>=C2=A05088 tty2=C2=A0=C2=A0=C2=A0=C2=A0 Sl+=C2=
=A0=C2=A0=C2=A0 0:27 /usr/lib/firefox/firefox -contentproc -childID 2 -isFo=
rBrowser -prefsLen 82 -prefMapSize 177920 -schedulerPrefs 0001,2 -parentBui=
ldID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/fir=
efox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true tab<br>=C2=
=A05094 tty2=C2=A0=C2=A0=C2=A0=C2=A0 Sl+=C2=A0=C2=A0=C2=A0 1:15 /usr/lib/fi=
refox/firefox -contentproc -childID 3 -isForBrowser -prefsLen 82 -prefMapSi=
ze 177920 -schedulerPrefs 0001,2 -parentBuildID 20190215001155 -greomni /us=
r/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /us=
r/lib/firefox/browser 4277 true tab<br>=C2=A05106 tty2=C2=A0=C2=A0=C2=A0=C2=
=A0 Sl+=C2=A0=C2=A0=C2=A0 1:02 /usr/lib/firefox/firefox -contentproc -child=
ID 4 -isForBrowser -prefsLen 82 -prefMapSize 177920 -schedulerPrefs 0001,2 =
-parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni /u=
sr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true t=
ab<br>=C2=A05188 tty2=C2=A0=C2=A0=C2=A0=C2=A0 Sl+=C2=A0=C2=A0=C2=A0 0:16 /u=
sr/lib/firefox/firefox -contentproc -childID 5 -isForBrowser -prefsLen 176 =
-prefMapSize 177920 -schedulerPrefs 0001,2 -parentBuildID 20190215001155 -g=
reomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -=
appdir /usr/lib/firefox/browser 4277 true tab<br>=C2=A05734 tty2=C2=A0=C2=
=A0=C2=A0=C2=A0 Sl+=C2=A0=C2=A0=C2=A0 0:07 /usr/lib/firefox/firefox -conten=
tproc -childID 6 -isForBrowser -prefsLen 6102 -prefMapSize 177920 -schedule=
rPrefs 0001,2 -parentBuildID 20190215001155 -greomni /usr/lib/firefox/omni.=
ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/brows=
er 4277 true tab<br></div><div><br></div><div>Then : <br></div><div><br></d=
iv><div>ps ax | grep [f]irefox | perl -ne &#39;@x =3D .words; @x.say&#39; <=
br></div><div><br></div><div>[4277 tty2 Sl+ 1:10 /usr/lib/firefox/firefox]<=
br>[4780 tty2 Sl+ 2:50 /usr/lib/firefox/firefox -contentproc -childID 1 -is=
ForBrowser -prefsLen 1 -prefMapSize 177920 -schedulerPrefs 0001,2 -parentBu=
ildID 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/fi=
refox/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true tab]<br>[5=
088 tty2 Sl+ 0:27 /usr/lib/firefox/firefox -contentproc -childID 2 -isForBr=
owser -prefsLen 82 -prefMapSize 177920 -schedulerPrefs 0001,2 -parentBuildI=
D 20190215001155 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefo=
x/browser/omni.ja -appdir /usr/lib/firefox/browser 4277 true tab]<br>[5094 =
tty2 Sl+ 1:18 /usr/lib/firefox/firefox -contentproc -childID 3 -isForBrowse=
r -prefsLen 82 -prefMapSize 177920 -schedulerPrefs 0001,2 -parentBuildID 20=
190215001155 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/br=
owser/omni.ja -appdir /usr/lib/firefox/browser 4277 true tab]<br>[5106 tty2=
 Sl+ 1:02 /usr/lib/firefox/firefox -contentproc -childID 4 -isForBrowser -p=
refsLen 82 -prefMapSize 177920 -schedulerPrefs 0001,2 -parentBuildID 201902=
15001155 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browse=
r/omni.ja -appdir /usr/lib/firefox/browser 4277 true tab]<br>[5188 tty2 Sl+=
 0:16 /usr/lib/firefox/firefox -contentproc -childID 5 -isForBrowser -prefs=
Len 176 -prefMapSize 177920 -schedulerPrefs 0001,2 -parentBuildID 201902150=
01155 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/o=
mni.ja -appdir /usr/lib/firefox/browser 4277 true tab]<br>[5734 tty2 Sl+ 0:=
07 /usr/lib/firefox/firefox -contentproc -childID 6 -isForBrowser -prefsLen=
 6102 -prefMapSize 177920 -schedulerPrefs 0001,2 -parentBuildID 20190215001=
155 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omn=
i.ja -appdir /usr/lib/firefox/browser 4277 true tab]</div><div><br></div><d=
iv>All looking good so far. what is it you&#39;re wanting from this data? <=
br></div><div><br></div></div></div></div><br><div class=3D"gmail_quote"><d=
iv dir=3D"ltr" class=3D"gmail_attr">On Fri, 15 Mar 2019 at 06:14, Todd Ches=
ter via perl6-users &lt;<a href=3D"mailto:perl6-users@perl.org">perl6-users=
@perl.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex">&gt;&gt; On Fri, 15 Mar 2019, 05:34 Todd Chester via perl6-users=
, <br>
&gt;&gt; &lt;<a href=3D"mailto:perl6-users@perl.org" target=3D"_blank">perl=
6-users@perl.org</a> &lt;mailto:<a href=3D"mailto:perl6-users@perl.org" tar=
get=3D"_blank">perl6-users@perl.org</a>&gt;&gt; wrote:<br>
&gt;&gt; <br>
&gt;&gt; <br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0On 3/14/19 10:05 PM, Todd Chester via perl6-use=
rs wrote:<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; Hi All,<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; What am I doing wrong here?<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; ps ax | grep [f]irefox | perl6 -ne &#39;m=
y @x =3D<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0$_.words[0].lines.reverse;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; print @x[0] ~ &quot;\n&quot;;&#39;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; 7380<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; 7581<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; 7698<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; 13023<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; 13767<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; 13908<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; Two problems:<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; 1) &quot;lines&quot; is putting everythin=
g into @x[0]<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; 2) &quot;reverse&quot; is ignoring me as =
there is no @x[1]. etc.<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; The result I want is 13908<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; Many thanks,<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 &gt; -T<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0And why do I have a broken pipe here?<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0$ ps ax | grep [f]irefox | perl6 -ne &#39;say<b=
r>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0$_.lines.sort.reverse.words[0];&#39;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A07380<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A07581<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A07698<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A013023<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A013767<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A022369<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0$ ps ax | grep [f]irefox | perl6 -ne &#39;say<b=
r>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0$_.lines.sort.reverse.words[0];&#39; | sort -r<=
br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0Failed to write bytes to filehandle: Broken pip=
e<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0in block &lt;unit&gt; at -e line =
1<br>
&gt;&gt; <br>
<br>
<br>
<br>
On 3/14/19 10:53 PM, Simon Proctor wrote:<br>
&gt; 6am here and I&#39;m not at a computer but I think your problem is try=
ing to <br>
&gt; use both -n which runs your code on each line of STDIN and lines.<br>
&gt; <br>
&gt; Try one or the other see what happens.<br>
&gt; <br>
&gt; Once I&#39;m ambulant and at a computer I&#39;ll poke at it myself.<br=
>
<br>
<br>
Thank you anyway.<br>
<br>
<br>
$ ps ax | grep [f]irefox | perl6 -n &#39;my @x =3D $_.words[0].lines.revers=
e; <br>
print @x[0] ~ &quot;\n&quot;;&#39;<br>
Could not open my @x =3D $_.words[0].lines.reverse; print @x[0] ~ &quot;\n&=
quot;;. <br>
Failed to stat file: no such file or directory<br>
<br>
$ ps ax | grep [f]irefox | perl6 -e &#39;my @x =3D $_.words[0].lines.revers=
e; <br>
print @x[0] ~ &quot;\n&quot;;&#39;<br>
No such method &#39;words&#39; for invocant of type &#39;Any&#39;<br>
=C2=A0 =C2=A0in block &lt;unit&gt; at -e line 1<br>
<br>
&gt; <br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature">Simon Proctor<br>Cognoscite aliquid novum cotidie<br><br><a=
 href=3D"http://www.khanate.co.uk/" target=3D"_blank">http://www.khanate.co=
..uk/</a></div>

--000000000000d3c7d305841ec1d8--
0
simon
3/15/2019 9:35:07 AM
--oC1+HKm2/end4ao3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Mar 14, 2019 at 11:14:17PM -0700, Todd Chester via perl6-users wrot=
e:
> > > On Fri, 15 Mar 2019, 05:34 Todd Chester via perl6-users,
> > > <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
> > >=20
> > >=20
> > >=20
> > >     On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:
> > >      > Hi All,
> > >      >
> > >      > What am I doing wrong here?
> > >      >
> > >      > ps ax | grep [f]irefox | perl6 -ne 'my @x =3D
> > >     $_.words[0].lines.reverse;
> > >      > print @x[0] ~ "\n";'
> > >      > 7380
> > >      > 7581
> > >      > 7698
> > >      > 13023
> > >      > 13767
> > >      > 13908
> > >      >
> > >      >
> > >      > Two problems:
> > >      >
> > >      > 1) "lines" is putting everything into @x[0]
> > >      >
> > >      > 2) "reverse" is ignoring me as there is no @x[1]. etc.
> > >      >
> > >      > The result I want is 13908
> > >      >
> > >      > Many thanks,
> > >      > -T
> > >=20
> > >     And why do I have a broken pipe here?
> > >=20
> > >     $ ps ax | grep [f]irefox | perl6 -ne 'say
> > >     $_.lines.sort.reverse.words[0];'
> > >     7380
> > >     7581
> > >     7698
> > >     13023
> > >     13767
> > >     22369
> > >=20
> > >     $ ps ax | grep [f]irefox | perl6 -ne 'say
> > >     $_.lines.sort.reverse.words[0];' | sort -r
> > >=20
> > >     Failed to write bytes to filehandle: Broken pipe
> > >         in block <unit> at -e line 1
> > >=20
>=20
>=20
>=20
> On 3/14/19 10:53 PM, Simon Proctor wrote:
> > 6am here and I'm not at a computer but I think your problem is trying to
> > use both -n which runs your code on each line of STDIN and lines.
> >=20
> > Try one or the other see what happens.
> >=20
> > Once I'm ambulant and at a computer I'll poke at it myself.
>=20
>=20
> Thank you anyway.
>=20
>=20
> $ ps ax | grep [f]irefox | perl6 -n 'my @x =3D $_.words[0].lines.reverse;
> print @x[0] ~ "\n";'
> Could not open my @x =3D $_.words[0].lines.reverse; print @x[0] ~ "\n";.
> Failed to stat file: no such file or directory
>=20
> $ ps ax | grep [f]irefox | perl6 -e 'my @x =3D $_.words[0].lines.reverse;
> print @x[0] ~ "\n";'
> No such method 'words' for invocant of type 'Any'
>   in block <unit> at -e line 1

So a couple of things here.

1. Learn to use pgrep instead of the myriad variations of ps | grep;
   pgrep has been standardized by POSIX for a long time and is almost
   certainly available in all the installations that you will ever need
   to touch[1].

2. Since you need to process all of the input lines as a whole, and not
   one by one, the "-n" option is not for you - it works on a single line
   at a time.  Yes, it is possible to do stuff using the END phaser, but
   in this case that would be overkill.  So you really want to run perl6
   without -n and then read all of the lines from its standard input
   stream.

3. The standard input stream in Perl 6 is called $*IN (think of it as
   mostly equivalent to what <<>> and <> would read from in Perl 5, and
   pretty much the same thing as Perl 5's STDIN).  So you want to run
   ".lines" on $*IN.

4. You only want to run ".words" on each of the items that ".lines"
   returned; then you want to convert each of the first words to
   an integer and then you want to sort them in reverse and get
   the first item.

So here are things step by step, first without using pgrep:

[roam@straylight ~]$ ps ax | grep -e '[z]sh' | perl6 -e 'dd $*IN.lines'
(" 3469 pts/19   Ss+    0:01 -zsh", " 3876 pts/17   Ss     0:00 -zsh", " 87=
82 pts/10   Ss     1:20 -zsh", "10041 pts/15   Ss     0:00 -zsh", "10257 pt=
s/24   Ss+    0:00 -zsh", "10523 pts/11   Ss     0:00 -zsh", "10728 pts/21 =
  Ss     0:00 -zsh", "10959 pts/12   Ss     0:00 -zsh", "11196 pts/22   Ss =
    0:00 -zsh", "11236 pts/18   Ss+    0:00 -zsh", "17512 pts/1    Ss     0=
:00 -zsh", "17905 pts/2    Ss     0:00 -zsh", "18089 pts/20   Ss+    0:00 -=
zsh", "18846 pts/5    Ss     0:00 -zsh", "19232 pts/6    Ss     0:00 -zsh",=
 "19808 pts/7    Ss+    0:02 -zsh", "20368 pts/13   Ss+    0:00 -zsh", "210=
46 pts/8    Ss     0:00 -zsh", "21232 pts/14   Ss     0:00 -zsh", "24099 pt=
s/9    Ss     0:00 -zsh", "29673 pts/16   Ss+    0:02 -zsh").Seq

OK, so we have the lines read from the standard input; let's see if we
can get the first word of each line:

[roam@straylight ~]$ ps ax | grep -e '[z]sh' | perl6 -e 'dd $*IN.lines.map:=
 *.words[0]'
("3469", "3876", "8782", "10041", "10257", "10523", "10728", "10959", "1119=
6", "11236", "17512", "17905", "18089", "18846", "19232", "19808", "20368",=
 "21046", "21232", "24099", "29673").Seq

Right, but we want them as integers, right?

[roam@straylight ~]$ ps ax | grep -e '[z]sh' | perl6 -e 'dd $*IN.lines.map:=
 *.words[0].Int'
(3469, 3876, 8782, 10041, 10257, 10523, 10728, 10959, 11196, 11236, 17512, =
17905, 18089, 18846, 19232, 19808, 20368, 21046, 21232, 24099, 29673).Seq

Let's sort them in reverse; note that we need to put the whole construct
so far in parentheses - we can't just stick a ".sort" at the end, since
it will operate only on a single integer, and that makes no sense.  We
need to take the whole sequence returned by ".map" and then sort it:

[roam@straylight ~]$ ps ax | grep -e '[z]sh' | perl6 -e 'dd ($*IN.lines.map=
: *.words[0].Int).sort.reverse'           =20
(29673, 24099, 21232, 21046, 20368, 19808, 19232, 18846, 18089, 17905, 1751=
2, 11236, 11196, 10959, 10728, 10523, 10257, 10041, 8782, 3876, 3469).Seq

And now to only get the largest process ID:

[roam@straylight ~]$ ps ax | grep -e '[z]sh' | perl6 -e 'dd ($*IN.lines.map=
: *.words[0].Int).sort.reverse[0]'
29673

Actually we can put the parentheses in a slightly different place, too:

[roam@straylight ~]$ ps ax | grep -e '[z]sh' | perl6 -e 'dd $*IN.lines.map(=
*.words[0].Int)'               =20
(3469, 3876, 8782, 10041, 10257, 10523, 10728, 10959, 11196, 11236, 17512, =
17905, 18089, 18846, 19232, 19808, 20368, 21046, 21232, 24099, 29673).Seq

OK, now let's see if pgrep would have helped:

[roam@straylight ~]$ pgrep zsh | perl6 -e 'dd $*IN.lines.map(*.Int).sort.re=
verse[0]'
29673

Yep, thought so :)  However... hm, you say you want the largest process
ID, but I'm not sure that this is *really* what you *need*; do you not
need the process that *started the most recently*?  (you know, on a long
running system the process IDs may wrap; this depends on the system,
some of them have really, really large process IDs, but some of them
also use them for other purposes, so still).  Unfortunately, this is
the point where the fun of using standardized utilities ends, since
for this next step it would be best to have a BSD-like ps(1) which
understands "-o" and has the "etime" format specifier.  So, left as
an exercise for the reader, how about this:

ps x -o pid,comm,etime | perl6 -e 'dd $*IN.lines.map({ /^ \s* $<pid> =3D [\=
d+] \s+ "zsh" \s .* \s+ $<elapsed> =3D [ <[- \d :]> + ] $/ ?? (~$/<pid> =3D=
> (0, 0, 0, |$/<elapsed>.split(/<[-:]>/).map(*.Int))[*-4..*]) !! Any }).gre=
p(*.defined).sort(*.value)[0].key'

Yes, I know it's a lot :) Take a look at it, see if you can break it
down into meaningful parts, see how those parts interplay; if you have
any questions, feel free to ask.  And, BTW, yes, on my Debian system
this showed a process with ID 29673 running for more than 20 days and
then a process with ID 23280 running for less than thirty minutes, so,
yes, this is what you need, not the largest process ID.

=2E..okay, okay, here goes the very complex line above changed into
a somewhat readable program:

#!/usr/bin/env perl6

use v6.c;

sub pad-elapsed($elapsed) {
	my @ints =3D $elapsed.split(/<[-:]>/).map: *.Int;
	my @padded =3D (0, 0, 0, |@ints);
	return @padded[*-4..*];
}

sub is-ours($line) {
	$line ~~ /^ \s* $<pid> =3D [\d+] \s+ "zsh" \s .* \s+ $<elapsed> =3D [ <[- =
\d :]> + ] $/
		?? (~$/<pid> =3D> pad-elapsed $/<elapsed>)
		!! Any
}

my @only-ours =3D $*IN.lines.map(&is-ours);
my @only-real-ones =3D @only-ours.grep(*.defined);
my @sorted =3D @only-real-ones.sort(*.value);
my $latest-pid =3D @sorted[0].key;

say $latest-pid;

Hope that helped!

G'luck,
Peter

[1] The "almost certainly" is because, yes, yes, I know, I also have that
    dusty old HP/UX crunching away in a customer's basement; still.

--=20
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} pp@storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

--oC1+HKm2/end4ao3
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEELuenpRf8EkzxFcNUZR7vsCUn3xMFAlyLdckACgkQZR7vsCUn
3xOFNA/+KbZhmnNfVCGuwJBDpGFAgFOd2ScOtu2UashaiDemTsgG2kTduXPl5pEP
penjVg7FfHdxPh57AH9lmt1w6ke7iyyk4Ef5sNJQ4vByoRgapWIEOnYPa13W+8F2
zrTcDtxv9fTk9Sjl9NxYeTIuxZkzkkccDLSgBP2LPljeZbqgVSyQCcOf0ru2KX9f
dGdjsiH4ixIokUYr84DP2Wik4Di+6dwJ5z3gWzPBRsK0HcEvAeCN+Cb0j6M+nSAP
2aVHO3NMOKju/Bs1qbkEakeMyk4PCrOprwmuzAKH0bGX5dMElu5gmWMLcbSTFHHU
7mzUljYq39LNBfmNBnrt6Bj+lnwItZ+XjcZBdEM4poNNImwi6wlXf8ikLsVEIxlv
tPOK23jdah4rE50qFk+1mdJHkUq+ZhEN32f6cmZ6m0ag6u8nNMbEW96+ORmQLnJ+
sj9to+AGrOpyj7XtZ7Ge1/J4En5OyNIDoSGWIHU2HQPY3wjwyeclLkboiWIWDAjW
1ie0g90V9PKPQII8K9hEo7KVHQgjzPw/byCF/Kuplaqo45dLg8Bmt8PKMD4h4mkR
cGhHT4zF1R0L+Tdu3PL7AV4cxFd3kSHR04Ocf+rmKjRpeJkrCzR13Tevz5VaMxbs
4F0gdrRJK1XUocAtSrFFaukLlA9sXmuPzRLOBqMsdFUgLdHx8R0=
=SSRA
-----END PGP SIGNATURE-----

--oC1+HKm2/end4ao3--
0
roam
3/15/2019 9:52:15 AM
--ghzN8eJ9Qlbqn3iT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Mar 15, 2019 at 11:52:15AM +0200, Peter Pentchev wrote:
[snip]
> 3. The standard input stream in Perl 6 is called $*IN (think of it as
>    mostly equivalent to what <<>> and <> would read from in Perl 5,

=2E..sorry about this part, I know it's not correct.

> and pretty much the same thing as Perl 5's STDIN.

=2E..this is the correct statement.

> sub is-ours($line) {
> 	$line ~~ /^ \s* $<pid> =3D [\d+] \s+ "zsh" \s .* \s+ $<elapsed> =3D [ <[=
- \d :]> + ] $/
> 		?? (~$/<pid> =3D> pad-elapsed $/<elapsed>)
> 		!! Any
> }

Of course, you may need to modify this a bit if you don't want to look
for "zsh" processes... :)

G'luck,
Peter

--=20
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} pp@storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

--ghzN8eJ9Qlbqn3iT
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEELuenpRf8EkzxFcNUZR7vsCUn3xMFAlyLeEMACgkQZR7vsCUn
3xMKkRAAuitpB7O1hZCPneJDK0m2nwL5LavKhVpOMYUvDQQq3UY5uzEwVlo4Biyb
3wf+XCOecsBtQ90XrbDvSK4gV+wnnXpmKFkvK28Jb4K+RbE9Qqy9cqhhsX/GJs/s
iVjhz3dAhM2DZf5wlxAEbttJVKOt8MW/wQMbY5H7g/F7xWf4XoARCfq+nVQdWzHt
rP4aKDcwbbHTQIAu1E2P2tyn/DGHAGKmBO2ShXMW2mdB3RmEGeCFQbW6Igetc/UV
5qUOU/5KMyvbeJUonj49o/29EZikI/dXdxUPCTLrSB7y6VwTgEojAUItd/Q64Lux
0DIdtObW1gW4S6VmWRCLPVyudjys1d/MOD5+uJqGLf/bk1J2oWygfbQ9rwr0cyYB
nwnut/sU+SfOILOsssgGV3x+omx94mD3edUqy/8f1ebNourLjoklMZR39Va0VGe1
xN1vA+dOCP4jxRNyMDG/GGhvPaUXDhcA0xXxWEQVkqB07HzM89zAuaia3riZLN7I
H8eyBlboRfIuQcDyVaalB8I8nG75gS3Dm20FIqKyVrdS9n16FuACHpOIDc0RxY9G
hKRs1FykXzbg9ByCatEh40Sr1Tgo1Ea5PoBrNX475X+64ipwD438UUIOkYCLtQVl
LIcW2Dq7tyNAM4UwHprlaaX59nSPLoJ0SUcQGCZZJGVHxIRMWmg=
=IfxT
-----END PGP SIGNATURE-----

--ghzN8eJ9Qlbqn3iT--
0
roam
3/15/2019 10:02:48 AM

On 3/15/19 2:35 AM, Simon Proctor wrote:
> All looking good so far. what is it you're wanting from this data?

Hi Simon,

Thank you!

What this is for is a backup routine.  I am checking for
the highest instance of any jammed running instances of
[xfa]dump.  If I find any, I "kill -9" it and walk backwards
until I have them all killed.

Once I am sure there are no long any jammed [xfa]dump's running,
then I cut loose my own instance of [xfa]dump.

This is bash script language.

GetLastDumpPID () {
    local Last=$(ps ax | grep "[d]ump " | awk '{print $1}' | 
/usr/bin/sort -r | /usr/bin/sed -n '1p')
    echo $Last
}


KillJammedDumps () {
    local PID="`GetLastDumpPID`"

    if [ -z "$PID" ]; then
       echo " ... No jammed dumps detected"

    else
       while [ -n "$PID" ]
          do
             echo " ... kill jammed dump PID <"$PID">"
             kill -9 $PID
             PID="`GetLastDumpPID`"
          done
    fi

    echo " "
}



-T
0
perl6
3/15/2019 2:49:09 PM

On 3/15/19 2:52 AM, Peter Pentchev wrote:
> 1. Learn to use pgrep instead of the myriad variations of ps | grep;
>     pgrep has been standardized by POSIX for a long time and is almost
>     certainly available in all the installations that you will ever need
>     to touch[1].

pgrep is interesting!  But it is not listing all the processes.  :'(

$ pgrep firefox
2135

$ ps ax | grep [f]irefox | awk '{print $1}'
2135
2239
2342
2425
0
perl6
3/15/2019 2:52:57 PM

On 3/15/19 2:52 AM, Peter Pentchev wrote:
> Hope that helped!
> 
> G'luck,
> Peter
> 
> [1] The "almost certainly" is because, yes, yes, I know, I also have that
>      dusty old HP/UX crunching away in a customer's basement; still.

Yes it does.  Thank you!

I remember zsh for my Solaris days.  Or at least I think I
remember that.  Time fades ...
0
perl6
3/15/2019 2:55:53 PM

On 3/15/19 3:02 AM, Peter Pentchev wrote:
> On Fri, Mar 15, 2019 at 11:52:15AM +0200, Peter Pentchev wrote:
> [snip]
>> 3. The standard input stream in Perl 6 is called $*IN (think of it as
>>     mostly equivalent to what <<>> and <> would read from in Perl 5,
> 
> ...sorry about this part, I know it's not correct.
> 
>> and pretty much the same thing as Perl 5's STDIN.
> 
> ...this is the correct statement.
> 
>> sub is-ours($line) {
>> 	$line ~~ /^ \s* $<pid> = [\d+] \s+ "zsh" \s .* \s+ $<elapsed> = [ <[- \d :]> + ] $/
>> 		?? (~$/<pid> => pad-elapsed $/<elapsed>)
>> 		!! Any
>> }
> 
> Of course, you may need to modify this a bit if you don't want to look
> for "zsh" processes... :)
> 
> G'luck,
> Peter
> 


Never did figure out why everything went into @x[0]
0
perl6
3/15/2019 2:58:11 PM
--AkbCVLjbJ9qUtAXD
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Mar 15, 2019 at 07:58:11AM -0700, Todd Chester via perl6-users wrot=
e:
>=20
>=20
> On 3/15/19 3:02 AM, Peter Pentchev wrote:
> > On Fri, Mar 15, 2019 at 11:52:15AM +0200, Peter Pentchev wrote:
> > [snip]
> > > 3. The standard input stream in Perl 6 is called $*IN (think of it as
> > >     mostly equivalent to what <<>> and <> would read from in Perl 5,
> >=20
> > ...sorry about this part, I know it's not correct.
> >=20
> > > and pretty much the same thing as Perl 5's STDIN.
> >=20
> > ...this is the correct statement.
> >=20
> > > sub is-ours($line) {
> > > 	$line ~~ /^ \s* $<pid> =3D [\d+] \s+ "zsh" \s .* \s+ $<elapsed> =3D =
[ <[- \d :]> + ] $/
> > > 		?? (~$/<pid> =3D> pad-elapsed $/<elapsed>)
> > > 		!! Any
> > > }
> >=20
> > Of course, you may need to modify this a bit if you don't want to look
> > for "zsh" processes... :)
> >=20
> > G'luck,
> > Peter
> >=20
>=20
>=20
> Never did figure out why everything went into @x[0]

What do you mean "everything"?  If you have an array (or a sequence) and
you sort it, you have another array (or sequence) with the same members,
but in a different order.  Then, if you only want the largest (or smallest,
or whatever) member, that means that you only want the first element of
the array.

G'luck,
Peter

--=20
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} pp@storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

--AkbCVLjbJ9qUtAXD
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEELuenpRf8EkzxFcNUZR7vsCUn3xMFAlyLySQACgkQZR7vsCUn
3xP6rw//UmN0a7JQ9YXcQx7qTD5Or9pmbX532YEDj+Fcj4VJKzABcxrZFSThci5R
Bw1W1EVJpyiAAwb3p1ydud6RF+zBYZSANLlmDJYSfmN3SFurDCpSZeI4VZ/UOOws
iI8x5yvKi+iDcAKMe+vyk/bL4qsNFUsfAgFq2nHUcnvwHRkdl+gtlvAQeCukOrzG
EE45MCpWVTFjZ8cs4xODPn1MeE9eAtvyVF7XXqSvfoof88kAblvSILaldwLQmryu
JfAjvbSiEC7wSdIbfnGzCT7h6Q7LIxZUffUF0m8EUDsfHOrdf4cQQskab52EF3+A
cll+2jsce9S9FBkcLTKZa5FWVBRngYgUp73M6WzoSyWOe/1MK0+Wc3PTn1aLk9Um
3NnitXmpiCP06rqdPDQMHDHEc+LYpCypvvRdnDeqAqR7qwsLReLwYN3WIaWD9saX
EFV1SDLcDozXzazwQ+9Ts+G2wmTtZvuI4m+CRqtGHEmEMRW3mid1RYt8UiXcnz/5
A0MZ65IarWQ2O9cum2LKTwdv8xLzdHWxbbmQjS4gnlRcbcifa2et23IA1PaCbeYI
GYEDAtTl6oBRRzf4LRRgoaVxuUZTlBPjTpW6KN+t/f029zClm6vE7P3rhUa6+wog
WuCnBiqVmPkYgZPRoz6KRyo6kWcO85bouhBr9WIyuMXpXOjwlQ8=
=de3y
-----END PGP SIGNATURE-----

--AkbCVLjbJ9qUtAXD--
0
roam
3/15/2019 3:47:54 PM
--vv4Sf/kQfcwinyKX
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Mar 15, 2019 at 07:52:57AM -0700, Todd Chester via perl6-users wrot=
e:
>=20
>=20
> On 3/15/19 2:52 AM, Peter Pentchev wrote:
> > 1. Learn to use pgrep instead of the myriad variations of ps | grep;
> >     pgrep has been standardized by POSIX for a long time and is almost
> >     certainly available in all the installations that you will ever need
> >     to touch[1].
>=20
> pgrep is interesting!  But it is not listing all the processes.  :'(
>=20
> $ pgrep firefox
> 2135
>=20
> $ ps ax | grep [f]irefox | awk '{print $1}'
> 2135
> 2239
> 2342
> 2425

So maybe play around with its options a bit; take a look at its manual page.
Also note that "ps ax | grep [f]irefox" (and I would VERY STRONGLY suggest
that you put the argument to "grep" in quotes to avoid the shell interpreti=
ng
it in weird and wonderful ways) might also match a process with a different
name that has "firefox" in its list of arguments - actually that's
the crazy reason for the '[f]irefox' hack, since this way the grep process
will not find itself (it's a variation of a "ps ax | grep firefox | grep -v=
 grep"
construct that people still seem to want to use).

G'luck,
Peter

--=20
Peter Pentchev  roam@{ringlet.net,debian.org,FreeBSD.org} pp@storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

--vv4Sf/kQfcwinyKX
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEELuenpRf8EkzxFcNUZR7vsCUn3xMFAlyLyxsACgkQZR7vsCUn
3xOZbA/6Aopw/Nh1Pr+L+0PeRNYR+HPaU3jit52IuMXBWnI1RDR5KmXmxYyUNJTB
KJ+J2kJEtZP2RchpdARz47OJAg9aiqyViIOFDG7UswVxUjwKQztOBjXcAe7IQn/D
lCeylod3Tjs3RsaTyxuqoSFS5wrCAkDE9EG8awST8I8vk0dumoxiLmoJBHSmzMmH
YVxd4F8siEVSTY+zVP2Nzkc3ACFAX/DeSjAIjf88xezxBrZ+XKWSeN9rGQQvThAn
BnQDjfwQPtzUhZSzzeepEVkjNN3NjHCDFkIxaiRbgXhEtPQ7N8EePFvK40oA9gdZ
sX8FxsS8gu5yz+d7iwR4CqeaZGSUaColG4DTkN1YSZxwkkcqIQn3ZBinr/n7Ooh6
3wtDiR3jGOAlEc45y+YpbQVIj+5ZoegfgfF8pIZdHK8qOJbvtpbWmOwcnyPsC+TB
HHoZ3mJ4rYIlS2U7Q7hV0BH24pM38ZMtzwQrGFsiZy3bYSiQt2M+VUWC9szmMy08
ZrIvkUEwHvl5cZJIDdEvU07fIARKqVRf2vvEQXzYTiLzDEdmJ4+7oUK6ob1AL3Aq
vSkJmW3yi3YahfSsQaQq+j4zw/XShNeDofePnTiJ4ZkOCz4nDnADe2J3OzcvuaV2
bAP7VIV7X7mVTShAupFwaNfT8hiVAaHU8pcR6P+65qHgliLhR3c=
=mqfW
-----END PGP SIGNATURE-----

--vv4Sf/kQfcwinyKX--
0
roam
3/15/2019 3:56:12 PM

On 3/15/19 7:58 AM, Todd Chester via perl6-users wrote:
> Never did figure out why everything went into @x[0]

The entire pipe gets put into @x[0].  @x[1] is uninitialized
0
perl6
3/15/2019 4:17:15 PM
On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:
> Hi All,
> 
> What am I doing wrong here?
> 
> ps ax | grep [f]irefox | perl6 -ne 'my @x = $_.words[0].lines.reverse; 
> print @x[0] ~ "\n";'
> 7380
> 7581
> 7698
> 13023
> 13767
> 13908
> 
> 
> Two problems:
> 
> 1) "lines" is putting everything into @x[0]
> 
> 2) "reverse" is ignoring me as there is no @x[1]. etc.
> 
> The result I want is 13908
> 
> Many thanks,
> -T

Follow up:

Timo over on the chat line helped with this
sweet way of doing it:

$ pgrep bash | perl6 -e 'my @x = lines.sort.reverse; print @x[0] ~ "\n" 
~  @x[1] ~ "\n";'
9873
2659

I did not realize the "lines" was a "slurp" to an array!

:-)
0
perl6
3/16/2019 1:38:09 AM
On 3/15/19 6:38 PM, ToddAndMargo via perl6-users wrote:
> On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:
>> Hi All,
>>
>> What am I doing wrong here?
>>
>> ps ax | grep [f]irefox | perl6 -ne 'my @x =3D $_.words[0].lines.revers=
e;=20
>> print @x[0] ~ "\n";'
>> 7380
>> 7581
>> 7698
>> 13023
>> 13767
>> 13908
>>
>>
>> Two problems:
>>
>> 1) "lines" is putting everything into @x[0]
>>
>> 2) "reverse" is ignoring me as there is no @x[1]. etc.
>>
>> The result I want is 13908
>>
>> Many thanks,
>> -T
>=20
> Follow up:
>=20
> Timo over on the chat line helped with this
> sweet way of doing it:
>=20
> $ pgrep bash | perl6 -e 'my @x =3D lines.sort.reverse; print @x[0] ~ "\=
n"=20
> ~=C2=A0 @x[1] ~ "\n";'
> 9873
> 2659
>=20
> I did not realize the "lines" was a "slurp" to an array!
>=20
> :-)


Okay, a little revision.  You are going to get the finger
wagged at you if $_ is empty.  So we need to add an "if" ...

Empty:
$ pgrep bashx | perl6 -e 'if {my @x =3D lines.sort.reverse; print @x[0] ~=
=20
"\n" ~  @x[1] ~ "\n";}'
=3D=3D=3DSORRY!=3D=3D=3D
Expression needs parens to avoid gobbling block
at -e:1
------> se; print @x[0] ~ "\n" ~  @x[1] ~ "\n";}=E2=8F=8F<EOL>
Missing block (apparently claimed by expression)
at -e:1
------> se; print @x[0] ~ "\n" ~  @x[1] ~ "\n";}=E2=8F=8F<EOL>


Empty with "if":
$ pgrep bashx | perl6 -e 'if my @x =3D lines.sort.reverse {print @x[0] ~ =

"\n" ~  @x[1] ~ "\n";}'



Not empty with "if":
$ pgrep bash | perl6 -e 'if my @x =3D lines.sort.reverse {print @x[0] ~=20
"\n" ~  @x[1] ~ "\n";}'
4780
2354
0
perl6
3/17/2019 3:54:34 AM
Reply: