×Hello Sime, On Sat, 29 Oct 2011 18:25:57 +0200 Sime Ramov <s...@ramov.com> wrote:
> Nothing to get excited about as this is just a beginning of my first > Perl script. Intention is to pipe it from some web accessible location > to perl upon first boot. > > I have difficulties with 'perlism' as I tend to only write small trivial > shell scripts. > > More specifically, the following line: > > foreach (@packages) { qx/pkg_add $_/; } > > Surely this is not an appropriate way for invoking interactive > system command to install packages? Would love to rewrite that. E.g. > I might add some interactive options to `pkg_add` which would render > this useless. Since you're not interested in the output of the pkg_add command, you should do: system("pkg_add", $_); See: http://shlomif-tech.livejournal.com/35301.html > > Next up, I need to *append* the following > > $DUID.a /storage ffs rw,nodev,nosuid,softdep 1 2 > > to `/etc/fstab` and am a bit lost as to what is the best way to > accomplish that. I could just echo it but then again I could just write > the whole thing in sh in the first place. > Do this: [CODE] open my $fstab_fh, '>>', '/etc/fstab' or die "Cannot open /etc/fstab for appending - $!"; print {$fstab_fh} "$DUID.a /storage ffs rw,nodev,nosuid,softdep 1 2\n"; close ($fstab_fh); [/CODE] For more information read about open in Perl here: * http://perldoc.perl.org/functions/open.html * http://perldoc.perl.org/perlopentut.html * http://perl-begin.org/ > Also this: > > my $DUID = qx/disklabel -n sd3 | grep duid | cut -d : -f 2/; > $DUID =~ s/^\s+|\s+$//; > > Could get rewritten more natively? With the grep and cut parts in Perl? Yes, you can do something like (untested naturally): my $DUID = (split(/:/, first { /duid/ } qx/dislabel -n sd3/)))[1]; $DUID =~ s/^\s+|\s+$//; > > These are just beginnings, at least one more function is needed for > putting all the configuration files from the storage volume to various > places in /etc and my home directory. > > Any other comments for improvements are more than welcome. Thanks. > Otherwise, it looks fine. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Best Introductory Programming Language - http://shlom.in/intro-lang Larry Wall has been changing the world. By modifying its very source code. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/