Basicly it removes the "ebuild U "(or what ever else is there)
from the begining and version numbers from the end of the
list of files genterated by `emerge -p > file.txt`
#!/usr/bin/perl #this program was created by John teBokkel aka Tanj #the program is used to remove "[ebuild N ]" from #the dependency list from `emerge -p packageName > file.txt` #also it removes version information from the end of the ebuild name use strict; our($garbage,$string,$file,$newfile); $file=$ARGV[0]; $newfile=$ARGV[1]; unless($file and $newfile) { die "missing argument\nagr1 source agr2 destination\n"; } open(FILE,"$file") || die "no such file\nagr1 source agr2 destination\ +n"; open(WORK,">$newfile") || die "could not create file\nagr1 source agr2 + destination\n"; while(<FILE>) { $garbage=s/\[(.*?)\]//; s/\-\d(.*?)\n//; $string=$_ . "\n"; if($garbage==1) { print WORK "$string"; } } close FILE; close WORK; print "done\n";
turns this
These are the packages that I would merge, in order: Calculating world dependencies *** Package in world file is not installed: kde-base/kde  ...done! [ebuild U ] media-sound/alsa-utils-0.9.0_rc8-r1 [0.9.0_rc8] [ebuild U ] sys-apps/file-3.41 [3.39] [ebuild U ] net-print/hpijs-1.3.1 [1.3] [ebuild U ] sys-apps/console-tools-0.3.2 [0.2.3-r4] [ebuild U ] media-sound/alsa-driver-0.9.0_rc8-r1 [0.9.0_rc8]
into this
media-sound/alsa-utils sys-apps/file net-print/hpijs sys-apps/console-tools media-sound/alsa-driver

Replies are listed 'Best First'.
Re: Gentoo Linux `emerge -p package >file`
by Aristotle (Chancellor) on Mar 16, 2003 at 00:42 UTC
    Too much effort.
    $ emerge -p package-name | perl -lne'print $1 if /^\[ [^]]+ \] \s* (.* +?) - \d/x'

    Makeshifts last the longest.

Re: Gentoo Linux `emerge -p package >file`
by Tomte (Priest) on Mar 15, 2003 at 19:42 UTC

    Cool script! Thanks for sharing it.

    Update:There are serious bugs in the open(...) statements in my code, I'm currently trying to get it to work, take it just as the (IMHO important) suggestion to allow pipes....

    Update II:pod rules ok. I read a few module docs, and here is what I wanted in the first place.

    A suggestion remains though, this is just a quick hack to show what I want: be able to pipe
    (e.g. emerge -p world | this_prog.pl):
    Here's the slightly changed code:

    #!/usr/bin/perl #this program was created by John teBokkel aka Tanj #the program is used to remove "[ebuild N ]" from #the dependency list from `emerge -p packageName > file.txt` #also it removes version information from the end of the ebuild name use strict; use FileHandle; our($garbage,$string,$file,$newfile); ($file, $newfile)=@ARGV; our($fhIn, $fhOut); if ($file) { $fhIn = new FileHandle "< $file"; die "no such file\nagr1 source agr2 destination\n" unless defined( +$fhIn); } else { $fhIn = new FileHandle; $fhIn->fdopen('STDIN',"r" ); } if ($newfile) { $fhOut = new FileHandle "> $newfile"; die "could not create file\nagr1 source agr2 destination\n" unless + defined($fhOut); } else { $fhOut = new FileHandle; $fhOut->fdopen('STDOUT', 'w'); } while(<$fhIn>) { $garbage=s/\[(.*?)\]//; s/\-\d(.*?)\n//; $string=$_ . "\n"; if($garbage==1) { print $fhOut "$string"; } } $fhIn->close(); $fhOut->close();

    Again thanks, I'll use it here and there :)

    regards,
    tomte