Steve_BZ has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys,

This seems to be what Perl was built for but is not immediately obvious to me what the correct way to do it is.

I'd value your input.

Regards

Steve

cat > wpa_supplicant/.config << "EOF" CONFIG_BACKEND=file CONFIG_CTRL_IFACE=y CONFIG_DEBUG_FILE=y CONFIG_DEBUG_SYSLOG=y CONFIG_DEBUG_SYSLOG_FACILITY=LOG_DAEMON CONFIG_DRIVER_NL80211=y CONFIG_DRIVER_WEXT=y CONFIG_DRIVER_WIRED=y CONFIG_EAP_GTC=y CONFIG_EAP_LEAP=y CONFIG_EAP_MD5=y CONFIG_EAP_MSCHAPV2=y CONFIG_EAP_OTP=y CONFIG_EAP_PEAP=y CONFIG_EAP_TLS=y CONFIG_EAP_TTLS=y CONFIG_IEEE8021X_EAPOL=y CONFIG_IPV6=y CONFIG_LIBNL32=y CONFIG_PEERKEY=y CONFIG_PKCS12=y CONFIG_READLINE=y CONFIG_SMARTCARD=y CONFIG_WPS=y CFLAGS += -I/usr/include/libnl3 EOF

Replies are listed 'Best First'.
Re: Perl and cat > wpa_supplicant/.config << "EOF"
by choroba (Cardinal) on Feb 08, 2014 at 12:13 UTC
    What are you trying to do? What is the real question?

    If you just want to write a Perl script that mimics the shell command you gave, you might try something along the following lines:

    #!/usr/bin/perl use warnings; use strict; open my $OUT, '>', 'wpa_supplicant/.config' or die $!; print {$OUT} << 'EOF'; CONFIG_BACKEND=file CONFIG_CTRL_IFACE=y CONFIG_DEBUG_FILE=y CONFIG_DEBUG_SYSLOG=y CONFIG_DEBUG_SYSLOG_FACILITY=LOG_DAEMON CONFIG_DRIVER_NL80211=y CONFIG_DRIVER_WEXT=y CONFIG_DRIVER_WIRED=y CONFIG_EAP_GTC=y CONFIG_EAP_LEAP=y CONFIG_EAP_MD5=y CONFIG_EAP_MSCHAPV2=y CONFIG_EAP_OTP=y CONFIG_EAP_PEAP=y CONFIG_EAP_TLS=y CONFIG_EAP_TTLS=y CONFIG_IEEE8021X_EAPOL=y CONFIG_IPV6=y CONFIG_LIBNL32=y CONFIG_PEERKEY=y CONFIG_PKCS12=y CONFIG_READLINE=y CONFIG_SMARTCARD=y CONFIG_WPS=y CFLAGS += -I/usr/include/libnl3 EOF close $OUT or die $!;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Hi Choroba,

      That's just what I'm looking for.

      Why does $out need the curly brackets?

      Can I also put lines like:

      CONFIG_PEERKEY=$yorn

      in the data?

      Regards

      Steve.

        Why does $out need the curly brackets?
        It does not. $OUT{wpa} would need them, though, if the file handles were stored in a hash. I use it just to make it visually more distinct from print $OUT, $data.

        See <<EOF on how to make a here document interpolate variables (basically, just use double quotes when introducing the terminating string).

        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ